LCOV - code coverage report
Current view: top level - gcc/rust/hir - rust-ast-lower.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 91.0 % 278 253
Test Date: 2025-01-18 13:11:24 Functions: 90.0 % 20 18
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : // Copyright (C) 2020-2025 Free Software Foundation, Inc.
       2                 :             : 
       3                 :             : // This file is part of GCC.
       4                 :             : 
       5                 :             : // GCC is free software; you can redistribute it and/or modify it under
       6                 :             : // the terms of the GNU General Public License as published by the Free
       7                 :             : // Software Foundation; either version 3, or (at your option) any later
       8                 :             : // version.
       9                 :             : 
      10                 :             : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      11                 :             : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12                 :             : // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      13                 :             : // for more details.
      14                 :             : 
      15                 :             : // You should have received a copy of the GNU General Public License
      16                 :             : // along with GCC; see the file COPYING3.  If not see
      17                 :             : // <http://www.gnu.org/licenses/>.
      18                 :             : 
      19                 :             : #include "rust-ast-lower.h"
      20                 :             : #include "rust-ast-lower-item.h"
      21                 :             : #include "rust-ast-lower-stmt.h"
      22                 :             : #include "rust-ast-lower-expr.h"
      23                 :             : #include "rust-ast-lower-block.h"
      24                 :             : #include "rust-ast-lower-type.h"
      25                 :             : #include "rust-ast-lower-pattern.h"
      26                 :             : #include "rust-ast-lower-struct-field-expr.h"
      27                 :             : 
      28                 :             : namespace Rust {
      29                 :             : namespace HIR {
      30                 :             : using HIR::ClosureParam;
      31                 :             : 
      32                 :             : Visibility
      33                 :       22832 : translate_visibility (const AST::Visibility &vis)
      34                 :             : {
      35                 :             :   // FIXME: How do we create a private visibility here? Is it always private if
      36                 :             :   // the AST vis is an error?
      37                 :             :   // FIXME: We need to add a `create_private()` static function to the
      38                 :             :   // AST::Visibility class and use it when the vis is empty in the parser...
      39                 :       22832 :   if (vis.is_error ())
      40                 :           0 :     return Visibility::create_error ();
      41                 :             : 
      42                 :       22832 :   switch (vis.get_vis_type ())
      43                 :             :     {
      44                 :        4645 :     case AST::Visibility::PUB:
      45                 :        4645 :       return Visibility (Visibility::VisType::PUBLIC);
      46                 :       18179 :     case AST::Visibility::PRIV:
      47                 :       18179 :     case AST::Visibility::PUB_SELF:
      48                 :       18179 :       return Visibility (Visibility::VisType::PRIVATE);
      49                 :           8 :     case AST::Visibility::PUB_CRATE:
      50                 :           8 :     case AST::Visibility::PUB_SUPER:
      51                 :           8 :     case AST::Visibility::PUB_IN_PATH:
      52                 :           8 :       return Visibility (Visibility::VisType::RESTRICTED,
      53                 :           8 :                          ASTLoweringSimplePath::translate (vis.get_path ()),
      54                 :           8 :                          vis.get_locus ());
      55                 :           0 :       break;
      56                 :             :     }
      57                 :             : 
      58                 :           0 :   return Visibility::create_error ();
      59                 :             : }
      60                 :             : 
      61                 :        3487 : ASTLowering::ASTLowering (AST::Crate &astCrate) : astCrate (astCrate) {}
      62                 :             : 
      63                 :        3487 : ASTLowering::~ASTLowering () {}
      64                 :             : 
      65                 :             : std::unique_ptr<HIR::Crate>
      66                 :        3487 : ASTLowering::Resolve (AST::Crate &astCrate)
      67                 :             : {
      68                 :        3487 :   ASTLowering resolver (astCrate);
      69                 :        3487 :   return resolver.go ();
      70                 :        3487 : }
      71                 :             : 
      72                 :             : std::unique_ptr<HIR::Crate>
      73                 :        3487 : ASTLowering::go ()
      74                 :             : {
      75                 :        3487 :   std::vector<std::unique_ptr<HIR::Item>> items;
      76                 :             : 
      77                 :       17274 :   for (auto &item : astCrate.items)
      78                 :             :     {
      79                 :       13787 :       auto translated = ASTLoweringItem::translate (*item);
      80                 :       13787 :       if (translated != nullptr)
      81                 :       13178 :         items.push_back (std::unique_ptr<HIR::Item> (translated));
      82                 :             :     }
      83                 :             : 
      84                 :        3487 :   auto mappings = Analysis::Mappings::get ();
      85                 :        3487 :   auto crate_num = mappings->get_current_crate ();
      86                 :        3487 :   Analysis::NodeMapping mapping (crate_num, astCrate.get_node_id (),
      87                 :             :                                  mappings->get_next_hir_id (crate_num),
      88                 :        3487 :                                  UNKNOWN_LOCAL_DEFID);
      89                 :             : 
      90                 :        3487 :   return std::unique_ptr<HIR::Crate> (
      91                 :        3487 :     new HIR::Crate (std::move (items), astCrate.get_inner_attrs (), mapping));
      92                 :        3487 : }
      93                 :             : 
      94                 :             : // rust-ast-lower-block.h
      95                 :             : void
      96                 :       12815 : ASTLoweringBlock::visit (AST::BlockExpr &expr)
      97                 :             : {
      98                 :       12815 :   auto label = lower_loop_label (expr.get_label ());
      99                 :             : 
     100                 :       12815 :   std::vector<std::unique_ptr<HIR::Stmt>> block_stmts;
     101                 :       12815 :   bool block_did_terminate = false;
     102                 :             : 
     103                 :       28967 :   for (auto &s : expr.get_statements ())
     104                 :             :     {
     105                 :       16152 :       if (s->get_ast_kind () == AST::Kind::MACRO_INVOCATION)
     106                 :           0 :         rust_fatal_error (
     107                 :           0 :           s->get_locus (),
     108                 :             :           "macro invocations should not get lowered to HIR - At "
     109                 :             :           "this point in "
     110                 :             :           "the pipeline, they should all have been expanded");
     111                 :             : 
     112                 :       16152 :       if (block_did_terminate)
     113                 :          18 :         rust_warning_at (s->get_locus (), 0, "unreachable statement");
     114                 :             : 
     115                 :       16152 :       bool terminated = false;
     116                 :       16152 :       auto translated_stmt = ASTLoweringStmt::translate (s.get (), &terminated);
     117                 :       16152 :       block_did_terminate |= terminated;
     118                 :             : 
     119                 :       16152 :       if (translated_stmt)
     120                 :       16147 :         block_stmts.push_back (std::unique_ptr<HIR::Stmt> (translated_stmt));
     121                 :             :     }
     122                 :             : 
     123                 :       12815 :   if (expr.has_tail_expr () && block_did_terminate)
     124                 :             :     {
     125                 :             :       // warning unreachable tail expressions
     126                 :          16 :       rust_warning_at (expr.get_tail_expr ().get_locus (), 0,
     127                 :             :                        "unreachable expression");
     128                 :             :     }
     129                 :             : 
     130                 :       12815 :   HIR::ExprWithoutBlock *tail_expr = nullptr;
     131                 :       12815 :   if (expr.has_tail_expr ())
     132                 :             :     {
     133                 :        8437 :       bool terminated = false;
     134                 :        8437 :       tail_expr = (HIR::ExprWithoutBlock *)
     135                 :        8437 :         ASTLoweringExpr::translate (expr.get_tail_expr (), &terminated);
     136                 :        8437 :       block_did_terminate |= terminated;
     137                 :             :     }
     138                 :             : 
     139                 :       12815 :   bool tail_reachable = !block_did_terminate;
     140                 :       12815 :   auto crate_num = mappings->get_current_crate ();
     141                 :       25630 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     142                 :       12815 :                                  mappings->get_next_hir_id (crate_num),
     143                 :       12815 :                                  UNKNOWN_LOCAL_DEFID);
     144                 :       12815 :   translated
     145                 :       12815 :     = new HIR::BlockExpr (mapping, std::move (block_stmts),
     146                 :       25630 :                           std::unique_ptr<HIR::ExprWithoutBlock> (tail_expr),
     147                 :       12815 :                           tail_reachable, expr.get_inner_attrs (),
     148                 :       12815 :                           expr.get_outer_attrs (), label,
     149                 :       25630 :                           expr.get_start_locus (), expr.get_end_locus ());
     150                 :             : 
     151                 :       12815 :   terminated = block_did_terminate;
     152                 :       12815 : }
     153                 :             : 
     154                 :             : void
     155                 :         300 : ASTLoweringIfBlock::visit (AST::IfExpr &expr)
     156                 :             : {
     157                 :         300 :   bool ignored_terminated = false;
     158                 :         300 :   HIR::Expr *condition = ASTLoweringExpr::translate (expr.get_condition_expr (),
     159                 :             :                                                      &ignored_terminated);
     160                 :         300 :   HIR::BlockExpr *block
     161                 :         300 :     = ASTLoweringBlock::translate (expr.get_if_block (), &ignored_terminated);
     162                 :             : 
     163                 :         300 :   auto crate_num = mappings->get_current_crate ();
     164                 :         600 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     165                 :         300 :                                  mappings->get_next_hir_id (crate_num),
     166                 :         300 :                                  UNKNOWN_LOCAL_DEFID);
     167                 :             : 
     168                 :         300 :   translated = new HIR::IfExpr (mapping, std::unique_ptr<HIR::Expr> (condition),
     169                 :         600 :                                 std::unique_ptr<HIR::BlockExpr> (block),
     170                 :         300 :                                 expr.get_locus ());
     171                 :         300 : }
     172                 :             : 
     173                 :             : void
     174                 :         347 : ASTLoweringIfBlock::visit (AST::IfExprConseqElse &expr)
     175                 :             : {
     176                 :         347 :   HIR::Expr *condition
     177                 :         347 :     = ASTLoweringExpr::translate (expr.get_condition_expr ());
     178                 :             : 
     179                 :         347 :   bool if_block_terminated = false;
     180                 :         347 :   bool else_block_termianted = false;
     181                 :             : 
     182                 :         347 :   HIR::BlockExpr *if_block
     183                 :         347 :     = ASTLoweringBlock::translate (expr.get_if_block (), &if_block_terminated);
     184                 :         347 :   HIR::ExprWithBlock *else_block
     185                 :         347 :     = ASTLoweringExprWithBlock::translate (expr.get_else_block (),
     186                 :             :                                            &else_block_termianted);
     187                 :             : 
     188                 :         347 :   terminated = if_block_terminated && else_block_termianted;
     189                 :             : 
     190                 :         347 :   auto crate_num = mappings->get_current_crate ();
     191                 :         694 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     192                 :         347 :                                  mappings->get_next_hir_id (crate_num),
     193                 :         347 :                                  UNKNOWN_LOCAL_DEFID);
     194                 :             : 
     195                 :         694 :   translated = new HIR::IfExprConseqElse (
     196                 :         347 :     mapping, std::unique_ptr<HIR::Expr> (condition),
     197                 :         694 :     std::unique_ptr<HIR::BlockExpr> (if_block),
     198                 :         694 :     std::unique_ptr<HIR::ExprWithBlock> (else_block), expr.get_locus ());
     199                 :         347 : }
     200                 :             : 
     201                 :             : void
     202                 :           0 : ASTLoweringIfLetBlock::visit (AST::IfLetExpr &expr)
     203                 :             : {
     204                 :           0 :   std::vector<std::unique_ptr<HIR::Pattern>> patterns;
     205                 :           0 :   for (auto &pattern : expr.get_patterns ())
     206                 :             :     {
     207                 :           0 :       HIR::Pattern *ptrn = ASTLoweringPattern::translate (*pattern);
     208                 :           0 :       patterns.push_back (std::unique_ptr<HIR::Pattern> (ptrn));
     209                 :             :     }
     210                 :           0 :   HIR::Expr *value_ptr = ASTLoweringExpr::translate (expr.get_value_expr ());
     211                 :             : 
     212                 :           0 :   bool ignored_terminated = false;
     213                 :           0 :   HIR::BlockExpr *block
     214                 :           0 :     = ASTLoweringBlock::translate (expr.get_if_block (), &ignored_terminated);
     215                 :             : 
     216                 :           0 :   auto crate_num = mappings->get_current_crate ();
     217                 :           0 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     218                 :           0 :                                  mappings->get_next_hir_id (crate_num),
     219                 :           0 :                                  UNKNOWN_LOCAL_DEFID);
     220                 :             : 
     221                 :           0 :   translated = new HIR::IfLetExpr (mapping, std::move (patterns),
     222                 :           0 :                                    std::unique_ptr<HIR::Expr> (value_ptr),
     223                 :           0 :                                    std::unique_ptr<HIR::BlockExpr> (block),
     224                 :           0 :                                    expr.get_locus ());
     225                 :           0 : }
     226                 :             : 
     227                 :             : void
     228                 :           2 : ASTLoweringIfLetBlock::visit (AST::IfLetExprConseqElse &expr)
     229                 :             : {
     230                 :           2 :   std::vector<std::unique_ptr<HIR::Pattern>> patterns;
     231                 :           4 :   for (auto &pattern : expr.get_patterns ())
     232                 :             :     {
     233                 :           2 :       HIR::Pattern *ptrn = ASTLoweringPattern::translate (*pattern);
     234                 :           2 :       patterns.push_back (std::unique_ptr<HIR::Pattern> (ptrn));
     235                 :             :     }
     236                 :           2 :   HIR::Expr *value_ptr = ASTLoweringExpr::translate (expr.get_value_expr ());
     237                 :             : 
     238                 :           2 :   bool ignored_terminated = false;
     239                 :           2 :   HIR::BlockExpr *block
     240                 :           2 :     = ASTLoweringBlock::translate (expr.get_if_block (), &ignored_terminated);
     241                 :             : 
     242                 :           2 :   HIR::ExprWithBlock *else_block
     243                 :           2 :     = ASTLoweringExprWithBlock::translate (expr.get_else_block (),
     244                 :             :                                            &ignored_terminated);
     245                 :             : 
     246                 :           2 :   rust_assert (else_block);
     247                 :             : 
     248                 :           2 :   auto crate_num = mappings->get_current_crate ();
     249                 :           4 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     250                 :           2 :                                  mappings->get_next_hir_id (crate_num),
     251                 :           2 :                                  UNKNOWN_LOCAL_DEFID);
     252                 :             : 
     253                 :           4 :   translated = new HIR::IfLetExprConseqElse (
     254                 :           6 :     mapping, std::move (patterns), std::unique_ptr<HIR::Expr> (value_ptr),
     255                 :           4 :     std::unique_ptr<HIR::BlockExpr> (block),
     256                 :           4 :     std::unique_ptr<HIR::ExprWithBlock> (else_block), expr.get_locus ());
     257                 :           2 : }
     258                 :             : 
     259                 :             : // rust-ast-lower-struct-field-expr.h
     260                 :             : 
     261                 :             : void
     262                 :        1281 : ASTLowerStructExprField::visit (AST::StructExprFieldIdentifierValue &field)
     263                 :             : {
     264                 :        1281 :   HIR::Expr *value = ASTLoweringExpr::translate (field.get_value ());
     265                 :             : 
     266                 :        1281 :   auto crate_num = mappings->get_current_crate ();
     267                 :        1281 :   Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
     268                 :        1281 :                                  mappings->get_next_hir_id (crate_num),
     269                 :        1281 :                                  UNKNOWN_LOCAL_DEFID);
     270                 :             : 
     271                 :        1281 :   translated = new HIR::StructExprFieldIdentifierValue (
     272                 :        1281 :     mapping, field.get_field_name (), std::unique_ptr<HIR::Expr> (value),
     273                 :        3843 :     field.get_locus ());
     274                 :        1281 : }
     275                 :             : 
     276                 :             : void
     277                 :          44 : ASTLowerStructExprField::visit (AST::StructExprFieldIndexValue &field)
     278                 :             : {
     279                 :          44 :   HIR::Expr *value = ASTLoweringExpr::translate (field.get_value ());
     280                 :             : 
     281                 :          44 :   auto crate_num = mappings->get_current_crate ();
     282                 :          44 :   Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
     283                 :          44 :                                  mappings->get_next_hir_id (crate_num),
     284                 :          44 :                                  UNKNOWN_LOCAL_DEFID);
     285                 :             : 
     286                 :          44 :   translated
     287                 :          44 :     = new HIR::StructExprFieldIndexValue (mapping, field.get_index (),
     288                 :          44 :                                           std::unique_ptr<HIR::Expr> (value),
     289                 :          44 :                                           field.get_locus ());
     290                 :          44 : }
     291                 :             : 
     292                 :             : void
     293                 :         211 : ASTLowerStructExprField::visit (AST::StructExprFieldIdentifier &field)
     294                 :             : {
     295                 :         211 :   auto crate_num = mappings->get_current_crate ();
     296                 :         211 :   Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
     297                 :         211 :                                  mappings->get_next_hir_id (crate_num),
     298                 :         211 :                                  UNKNOWN_LOCAL_DEFID);
     299                 :             : 
     300                 :         211 :   translated
     301                 :         211 :     = new HIR::StructExprFieldIdentifier (mapping, field.get_field_name (),
     302                 :         422 :                                           field.get_locus ());
     303                 :         211 : }
     304                 :             : 
     305                 :             : // rust-ast-lower-block.h
     306                 :             : 
     307                 :             : void
     308                 :          35 : ASTLoweringExprWithBlock::visit (AST::WhileLoopExpr &expr)
     309                 :             : {
     310                 :          35 :   HIR::BlockExpr *loop_block
     311                 :          35 :     = ASTLoweringBlock::translate (expr.get_loop_block (), &terminated);
     312                 :             : 
     313                 :          35 :   HIR::LoopLabel loop_label = lower_loop_label (expr.get_loop_label ());
     314                 :          35 :   HIR::Expr *loop_condition
     315                 :          35 :     = ASTLoweringExpr::translate (expr.get_predicate_expr (), &terminated);
     316                 :             : 
     317                 :          35 :   auto crate_num = mappings->get_current_crate ();
     318                 :          70 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     319                 :          35 :                                  mappings->get_next_hir_id (crate_num),
     320                 :          35 :                                  UNKNOWN_LOCAL_DEFID);
     321                 :             : 
     322                 :          35 :   translated
     323                 :          35 :     = new HIR::WhileLoopExpr (mapping,
     324                 :          35 :                               std::unique_ptr<HIR::Expr> (loop_condition),
     325                 :          70 :                               std::unique_ptr<HIR::BlockExpr> (loop_block),
     326                 :             :                               expr.get_locus (), std::move (loop_label),
     327                 :          70 :                               expr.get_outer_attrs ());
     328                 :          35 : }
     329                 :             : 
     330                 :             : void
     331                 :           0 : ASTLoweringExprWithBlock::visit (AST::ForLoopExpr &expr)
     332                 :             : {
     333                 :             :   // TODO FIXME
     334                 :             : 
     335                 :             :   // HIR::BlockExpr *loop_block
     336                 :             :   //   = ASTLoweringBlock::translate (expr.get_loop_block ().get (),
     337                 :             :   //   &terminated);
     338                 :             :   // HIR::LoopLabel loop_label = lower_loop_label (expr.get_loop_label ());
     339                 :             :   // HIR::Expr *iterator_expr
     340                 :             :   //   = ASTLoweringExpr::translate (expr.get_iterator_expr ().get (),
     341                 :             :   //                              &terminated);
     342                 :             :   // HIR::Pattern *loop_pattern
     343                 :             :   //   = ASTLoweringPattern::translate (expr.get_pattern ().get ());
     344                 :             : 
     345                 :             :   // auto crate_num = mappings->get_current_crate ();
     346                 :             :   // Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     347                 :             :   //                             mappings->get_next_hir_id (crate_num),
     348                 :             :   //                             UNKNOWN_LOCAL_DEFID);
     349                 :             : 
     350                 :           0 :   gcc_unreachable ();
     351                 :             : }
     352                 :             : 
     353                 :             : void
     354                 :         198 : ASTLoweringExprWithBlock::visit (AST::MatchExpr &expr)
     355                 :             : {
     356                 :         198 :   HIR::Expr *branch_value
     357                 :         198 :     = ASTLoweringExpr::translate (expr.get_scrutinee_expr ());
     358                 :             : 
     359                 :         198 :   std::vector<HIR::MatchCase> match_arms;
     360                 :         695 :   for (auto &match_case : expr.get_match_cases ())
     361                 :             :     {
     362                 :         497 :       HIR::Expr *kase_expr
     363                 :         497 :         = ASTLoweringExpr::translate (match_case.get_expr ());
     364                 :             : 
     365                 :         497 :       HIR::Expr *kase_guard_expr = nullptr;
     366                 :         497 :       if (match_case.get_arm ().has_match_arm_guard ())
     367                 :             :         {
     368                 :           1 :           kase_guard_expr = ASTLoweringExpr::translate (
     369                 :             :             match_case.get_arm ().get_guard_expr ());
     370                 :             :         }
     371                 :             : 
     372                 :         497 :       std::vector<std::unique_ptr<HIR::Pattern>> match_arm_patterns;
     373                 :         994 :       for (auto &pattern : match_case.get_arm ().get_patterns ())
     374                 :             :         {
     375                 :         497 :           HIR::Pattern *ptrn = ASTLoweringPattern::translate (*pattern);
     376                 :         497 :           match_arm_patterns.push_back (std::unique_ptr<HIR::Pattern> (ptrn));
     377                 :             :         }
     378                 :             : 
     379                 :         497 :       HIR::MatchArm arm (std::move (match_arm_patterns), expr.get_locus (),
     380                 :         497 :                          std::unique_ptr<HIR::Expr> (kase_guard_expr),
     381                 :         497 :                          match_case.get_arm ().get_outer_attrs ());
     382                 :             : 
     383                 :         497 :       auto crate_num = mappings->get_current_crate ();
     384                 :         994 :       Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     385                 :         497 :                                      mappings->get_next_hir_id (crate_num),
     386                 :         497 :                                      UNKNOWN_LOCAL_DEFID);
     387                 :             : 
     388                 :         497 :       HIR::MatchCase kase (std::move (mapping), std::move (arm),
     389                 :         497 :                            std::unique_ptr<HIR::Expr> (kase_expr));
     390                 :         497 :       match_arms.push_back (std::move (kase));
     391                 :         497 :     }
     392                 :             : 
     393                 :         198 :   auto crate_num = mappings->get_current_crate ();
     394                 :         396 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     395                 :         198 :                                  mappings->get_next_hir_id (crate_num),
     396                 :         198 :                                  UNKNOWN_LOCAL_DEFID);
     397                 :             : 
     398                 :         198 :   translated
     399                 :         198 :     = new HIR::MatchExpr (mapping, std::unique_ptr<HIR::Expr> (branch_value),
     400                 :         198 :                           std::move (match_arms), expr.get_inner_attrs (),
     401                 :         396 :                           expr.get_outer_attrs (), expr.get_locus ());
     402                 :         198 : }
     403                 :             : 
     404                 :             : // rust-ast-lower-expr.h
     405                 :             : 
     406                 :             : void
     407                 :       11241 : ASTLowerPathInExpression::visit (AST::PathInExpression &expr)
     408                 :             : {
     409                 :       11241 :   std::vector<HIR::PathExprSegment> path_segments;
     410                 :       11241 :   auto &segments = expr.get_segments ();
     411                 :       24925 :   for (auto &s : segments)
     412                 :             :     {
     413                 :       13684 :       path_segments.push_back (lower_path_expr_seg ((s)));
     414                 :             : 
     415                 :             :       // insert the mappings for the segment
     416                 :       13684 :       HIR::PathExprSegment *lowered_seg = &path_segments.back ();
     417                 :       13684 :       mappings->insert_hir_path_expr_seg (lowered_seg);
     418                 :             :     }
     419                 :       11241 :   auto crate_num = mappings->get_current_crate ();
     420                 :       22482 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     421                 :       11241 :                                  mappings->get_next_hir_id (crate_num),
     422                 :       11241 :                                  UNKNOWN_LOCAL_DEFID);
     423                 :             : 
     424                 :       22482 :   translated = new HIR::PathInExpression (mapping, std::move (path_segments),
     425                 :             :                                           expr.get_locus (),
     426                 :       11241 :                                           expr.opening_scope_resolution ());
     427                 :       11241 : }
     428                 :             : 
     429                 :             : HIR::QualifiedPathType
     430                 :          80 : ASTLoweringBase::lower_qual_path_type (AST::QualifiedPathType &qualified_type)
     431                 :             : {
     432                 :          80 :   HIR::Type *type = ASTLoweringType::translate (qualified_type.get_type ());
     433                 :          80 :   HIR::TypePath *trait
     434                 :          80 :     = qualified_type.has_as_clause ()
     435                 :          80 :         ? ASTLowerTypePath::translate (qualified_type.get_as_type_path ())
     436                 :          80 :         : nullptr;
     437                 :             : 
     438                 :          80 :   auto crate_num = mappings->get_current_crate ();
     439                 :          80 :   Analysis::NodeMapping mapping (crate_num, qualified_type.get_node_id (),
     440                 :          80 :                                  mappings->get_next_hir_id (crate_num),
     441                 :          80 :                                  UNKNOWN_LOCAL_DEFID);
     442                 :             : 
     443                 :          80 :   return HIR::QualifiedPathType (mapping, std::unique_ptr<HIR::Type> (type),
     444                 :          80 :                                  std::unique_ptr<HIR::TypePath> (trait),
     445                 :          80 :                                  qualified_type.get_locus ());
     446                 :             : }
     447                 :             : 
     448                 :             : void
     449                 :          80 : ASTLowerQualPathInExpression::visit (AST::QualifiedPathInExpression &expr)
     450                 :             : {
     451                 :          80 :   HIR::QualifiedPathType qual_path_type
     452                 :          80 :     = lower_qual_path_type (expr.get_qualified_path_type ());
     453                 :             : 
     454                 :          80 :   std::vector<HIR::PathExprSegment> path_segments;
     455                 :          80 :   auto &segments = expr.get_segments ();
     456                 :         160 :   for (auto &s : segments)
     457                 :             :     {
     458                 :          80 :       path_segments.push_back (lower_path_expr_seg ((s)));
     459                 :             : 
     460                 :             :       // insert the mappings for the segment
     461                 :          80 :       HIR::PathExprSegment *lowered_seg = &path_segments.back ();
     462                 :          80 :       mappings->insert_hir_path_expr_seg (lowered_seg);
     463                 :             :     }
     464                 :             : 
     465                 :          80 :   auto crate_num = mappings->get_current_crate ();
     466                 :         160 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     467                 :          80 :                                  mappings->get_next_hir_id (crate_num),
     468                 :          80 :                                  UNKNOWN_LOCAL_DEFID);
     469                 :             : 
     470                 :          80 :   translated = new HIR::QualifiedPathInExpression (mapping, qual_path_type,
     471                 :             :                                                    std::move (path_segments),
     472                 :             :                                                    expr.get_locus (),
     473                 :         160 :                                                    expr.get_outer_attrs ());
     474                 :          80 : }
     475                 :             : 
     476                 :             : ClosureParam
     477                 :          53 : ASTLoweringBase::lower_closure_param (AST::ClosureParam &param)
     478                 :             : {
     479                 :          53 :   HIR::Pattern *param_pattern
     480                 :          53 :     = ASTLoweringPattern::translate (param.get_pattern ());
     481                 :             : 
     482                 :          53 :   HIR::Type *param_type = param.has_type_given ()
     483                 :          53 :                             ? ASTLoweringType::translate (param.get_type ())
     484                 :          53 :                             : nullptr;
     485                 :             : 
     486                 :         106 :   return HIR::ClosureParam (std::unique_ptr<HIR::Pattern> (param_pattern),
     487                 :             :                             param.get_locus (),
     488                 :          53 :                             param.has_type_given ()
     489                 :         106 :                               ? std::unique_ptr<HIR::Type> (param_type)
     490                 :             :                               : nullptr,
     491                 :         159 :                             param.get_outer_attrs ());
     492                 :             : }
     493                 :             : 
     494                 :             : } // namespace HIR
     495                 :             : } // namespace Rust
        

Generated by: LCOV version 2.1-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.