LCOV - code coverage report
Current view: top level - gcc/rust/hir - rust-ast-lower.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 90.8 % 284 258
Test Date: 2024-04-20 14:03:02 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-2024 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                 :       22779 : 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                 :       22779 :   if (vis.is_error ())
      40                 :           0 :     return Visibility::create_error ();
      41                 :             : 
      42                 :       22779 :   switch (vis.get_vis_type ())
      43                 :             :     {
      44                 :        4617 :     case AST::Visibility::PUB:
      45                 :        4617 :       return Visibility (Visibility::VisType::PUBLIC);
      46                 :       18154 :     case AST::Visibility::PRIV:
      47                 :       18154 :     case AST::Visibility::PUB_SELF:
      48                 :       18154 :       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                 :        3474 : ASTLowering::ASTLowering (AST::Crate &astCrate) : astCrate (astCrate) {}
      62                 :             : 
      63                 :        3474 : ASTLowering::~ASTLowering () {}
      64                 :             : 
      65                 :             : std::unique_ptr<HIR::Crate>
      66                 :        3474 : ASTLowering::Resolve (AST::Crate &astCrate)
      67                 :             : {
      68                 :        3474 :   ASTLowering resolver (astCrate);
      69                 :        3474 :   return resolver.go ();
      70                 :        3474 : }
      71                 :             : 
      72                 :             : std::unique_ptr<HIR::Crate>
      73                 :        3474 : ASTLowering::go ()
      74                 :             : {
      75                 :        3474 :   std::vector<std::unique_ptr<HIR::Item>> items;
      76                 :             : 
      77                 :       17229 :   for (auto it = astCrate.items.begin (); it != astCrate.items.end (); it++)
      78                 :             :     {
      79                 :       13755 :       auto translated = ASTLoweringItem::translate (it->get ());
      80                 :       13755 :       if (translated != nullptr)
      81                 :       13153 :         items.push_back (std::unique_ptr<HIR::Item> (translated));
      82                 :             :     }
      83                 :             : 
      84                 :        3474 :   auto mappings = Analysis::Mappings::get ();
      85                 :        3474 :   auto crate_num = mappings->get_current_crate ();
      86                 :        3474 :   Analysis::NodeMapping mapping (crate_num, astCrate.get_node_id (),
      87                 :             :                                  mappings->get_next_hir_id (crate_num),
      88                 :        3474 :                                  UNKNOWN_LOCAL_DEFID);
      89                 :             : 
      90                 :        3474 :   return std::unique_ptr<HIR::Crate> (
      91                 :        3474 :     new HIR::Crate (std::move (items), astCrate.get_inner_attrs (), mapping));
      92                 :        3474 : }
      93                 :             : 
      94                 :             : // rust-ast-lower-block.h
      95                 :             : void
      96                 :       12784 : ASTLoweringBlock::visit (AST::BlockExpr &expr)
      97                 :             : {
      98                 :       12784 :   auto label = lower_loop_label (expr.get_label ());
      99                 :             : 
     100                 :       12784 :   std::vector<std::unique_ptr<HIR::Stmt>> block_stmts;
     101                 :       12784 :   bool block_did_terminate = false;
     102                 :             : 
     103                 :       28917 :   for (auto &s : expr.get_statements ())
     104                 :             :     {
     105                 :       16133 :       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                 :       16133 :       if (block_did_terminate)
     113                 :          18 :         rust_warning_at (s->get_locus (), 0, "unreachable statement");
     114                 :             : 
     115                 :       16133 :       bool terminated = false;
     116                 :       16133 :       auto translated_stmt = ASTLoweringStmt::translate (s.get (), &terminated);
     117                 :       16133 :       block_did_terminate |= terminated;
     118                 :             : 
     119                 :       16133 :       if (translated_stmt)
     120                 :       16128 :         block_stmts.push_back (std::unique_ptr<HIR::Stmt> (translated_stmt));
     121                 :             :     }
     122                 :             : 
     123                 :       12784 :   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                 :       12784 :   HIR::ExprWithoutBlock *tail_expr = nullptr;
     131                 :       12784 :   if (expr.has_tail_expr ())
     132                 :             :     {
     133                 :        8429 :       bool terminated = false;
     134                 :        8429 :       tail_expr = (HIR::ExprWithoutBlock *)
     135                 :        8429 :         ASTLoweringExpr::translate (expr.get_tail_expr ().get (), &terminated);
     136                 :        8429 :       block_did_terminate |= terminated;
     137                 :             :     }
     138                 :             : 
     139                 :       12784 :   bool tail_reachable = !block_did_terminate;
     140                 :       12784 :   auto crate_num = mappings->get_current_crate ();
     141                 :       25568 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     142                 :       12784 :                                  mappings->get_next_hir_id (crate_num),
     143                 :       12784 :                                  UNKNOWN_LOCAL_DEFID);
     144                 :       12784 :   translated
     145                 :       12784 :     = new HIR::BlockExpr (mapping, std::move (block_stmts),
     146                 :       25568 :                           std::unique_ptr<HIR::ExprWithoutBlock> (tail_expr),
     147                 :       12784 :                           tail_reachable, expr.get_inner_attrs (),
     148                 :       12784 :                           expr.get_outer_attrs (), label,
     149                 :       25568 :                           expr.get_start_locus (), expr.get_end_locus ());
     150                 :             : 
     151                 :       12784 :   terminated = block_did_terminate;
     152                 :       12784 : }
     153                 :             : 
     154                 :             : void
     155                 :         300 : ASTLoweringIfBlock::visit (AST::IfExpr &expr)
     156                 :             : {
     157                 :         300 :   bool ignored_terminated = false;
     158                 :         300 :   HIR::Expr *condition
     159                 :         300 :     = ASTLoweringExpr::translate (expr.get_condition_expr ().get (),
     160                 :             :                                   &ignored_terminated);
     161                 :         300 :   HIR::BlockExpr *block
     162                 :         300 :     = ASTLoweringBlock::translate (expr.get_if_block ().get (),
     163                 :             :                                    &ignored_terminated);
     164                 :             : 
     165                 :         300 :   auto crate_num = mappings->get_current_crate ();
     166                 :         600 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     167                 :         300 :                                  mappings->get_next_hir_id (crate_num),
     168                 :         300 :                                  UNKNOWN_LOCAL_DEFID);
     169                 :             : 
     170                 :         300 :   translated = new HIR::IfExpr (mapping, std::unique_ptr<HIR::Expr> (condition),
     171                 :         600 :                                 std::unique_ptr<HIR::BlockExpr> (block),
     172                 :         300 :                                 expr.get_locus ());
     173                 :         300 : }
     174                 :             : 
     175                 :             : void
     176                 :         347 : ASTLoweringIfBlock::visit (AST::IfExprConseqElse &expr)
     177                 :             : {
     178                 :         347 :   HIR::Expr *condition
     179                 :         347 :     = ASTLoweringExpr::translate (expr.get_condition_expr ().get ());
     180                 :             : 
     181                 :         347 :   bool if_block_terminated = false;
     182                 :         347 :   bool else_block_termianted = false;
     183                 :             : 
     184                 :         347 :   HIR::BlockExpr *if_block
     185                 :         347 :     = ASTLoweringBlock::translate (expr.get_if_block ().get (),
     186                 :             :                                    &if_block_terminated);
     187                 :         347 :   HIR::ExprWithBlock *else_block
     188                 :         347 :     = ASTLoweringExprWithBlock::translate (expr.get_else_block ().get (),
     189                 :             :                                            &else_block_termianted);
     190                 :             : 
     191                 :         347 :   terminated = if_block_terminated && else_block_termianted;
     192                 :             : 
     193                 :         347 :   auto crate_num = mappings->get_current_crate ();
     194                 :         694 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     195                 :         347 :                                  mappings->get_next_hir_id (crate_num),
     196                 :         347 :                                  UNKNOWN_LOCAL_DEFID);
     197                 :             : 
     198                 :         694 :   translated = new HIR::IfExprConseqElse (
     199                 :         347 :     mapping, std::unique_ptr<HIR::Expr> (condition),
     200                 :         694 :     std::unique_ptr<HIR::BlockExpr> (if_block),
     201                 :         694 :     std::unique_ptr<HIR::ExprWithBlock> (else_block), expr.get_locus ());
     202                 :         347 : }
     203                 :             : 
     204                 :             : void
     205                 :           0 : ASTLoweringIfLetBlock::visit (AST::IfLetExpr &expr)
     206                 :             : {
     207                 :           0 :   std::vector<std::unique_ptr<HIR::Pattern>> patterns;
     208                 :           0 :   for (auto &pattern : expr.get_patterns ())
     209                 :             :     {
     210                 :           0 :       HIR::Pattern *ptrn = ASTLoweringPattern::translate (pattern.get ());
     211                 :           0 :       patterns.push_back (std::unique_ptr<HIR::Pattern> (ptrn));
     212                 :             :     }
     213                 :           0 :   HIR::Expr *value_ptr
     214                 :           0 :     = ASTLoweringExpr::translate (expr.get_value_expr ().get ());
     215                 :             : 
     216                 :           0 :   bool ignored_terminated = false;
     217                 :           0 :   HIR::BlockExpr *block
     218                 :           0 :     = ASTLoweringBlock::translate (expr.get_if_block ().get (),
     219                 :             :                                    &ignored_terminated);
     220                 :             : 
     221                 :           0 :   auto crate_num = mappings->get_current_crate ();
     222                 :           0 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     223                 :           0 :                                  mappings->get_next_hir_id (crate_num),
     224                 :           0 :                                  UNKNOWN_LOCAL_DEFID);
     225                 :             : 
     226                 :           0 :   translated = new HIR::IfLetExpr (mapping, std::move (patterns),
     227                 :           0 :                                    std::unique_ptr<HIR::Expr> (value_ptr),
     228                 :           0 :                                    std::unique_ptr<HIR::BlockExpr> (block),
     229                 :           0 :                                    expr.get_locus ());
     230                 :           0 : }
     231                 :             : 
     232                 :             : void
     233                 :           2 : ASTLoweringIfLetBlock::visit (AST::IfLetExprConseqElse &expr)
     234                 :             : {
     235                 :           2 :   std::vector<std::unique_ptr<HIR::Pattern>> patterns;
     236                 :           4 :   for (auto &pattern : expr.get_patterns ())
     237                 :             :     {
     238                 :           2 :       HIR::Pattern *ptrn = ASTLoweringPattern::translate (pattern.get ());
     239                 :           2 :       patterns.push_back (std::unique_ptr<HIR::Pattern> (ptrn));
     240                 :             :     }
     241                 :           2 :   HIR::Expr *value_ptr
     242                 :           2 :     = ASTLoweringExpr::translate (expr.get_value_expr ().get ());
     243                 :             : 
     244                 :           2 :   bool ignored_terminated = false;
     245                 :           2 :   HIR::BlockExpr *block
     246                 :           2 :     = ASTLoweringBlock::translate (expr.get_if_block ().get (),
     247                 :             :                                    &ignored_terminated);
     248                 :             : 
     249                 :           2 :   HIR::ExprWithBlock *else_block
     250                 :           2 :     = ASTLoweringExprWithBlock::translate (expr.get_else_block ().get (),
     251                 :             :                                            &ignored_terminated);
     252                 :             : 
     253                 :           2 :   rust_assert (else_block);
     254                 :             : 
     255                 :           2 :   auto crate_num = mappings->get_current_crate ();
     256                 :           4 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     257                 :           2 :                                  mappings->get_next_hir_id (crate_num),
     258                 :           2 :                                  UNKNOWN_LOCAL_DEFID);
     259                 :             : 
     260                 :           4 :   translated = new HIR::IfLetExprConseqElse (
     261                 :           6 :     mapping, std::move (patterns), std::unique_ptr<HIR::Expr> (value_ptr),
     262                 :           4 :     std::unique_ptr<HIR::BlockExpr> (block),
     263                 :           4 :     std::unique_ptr<HIR::ExprWithBlock> (else_block), expr.get_locus ());
     264                 :           2 : }
     265                 :             : 
     266                 :             : // rust-ast-lower-struct-field-expr.h
     267                 :             : 
     268                 :             : void
     269                 :        1279 : ASTLowerStructExprField::visit (AST::StructExprFieldIdentifierValue &field)
     270                 :             : {
     271                 :        1279 :   HIR::Expr *value = ASTLoweringExpr::translate (field.get_value ().get ());
     272                 :             : 
     273                 :        1279 :   auto crate_num = mappings->get_current_crate ();
     274                 :        1279 :   Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
     275                 :        1279 :                                  mappings->get_next_hir_id (crate_num),
     276                 :        1279 :                                  UNKNOWN_LOCAL_DEFID);
     277                 :             : 
     278                 :        1279 :   translated = new HIR::StructExprFieldIdentifierValue (
     279                 :        1279 :     mapping, field.get_field_name (), std::unique_ptr<HIR::Expr> (value),
     280                 :        3837 :     field.get_locus ());
     281                 :        1279 : }
     282                 :             : 
     283                 :             : void
     284                 :          44 : ASTLowerStructExprField::visit (AST::StructExprFieldIndexValue &field)
     285                 :             : {
     286                 :          44 :   HIR::Expr *value = ASTLoweringExpr::translate (field.get_value ().get ());
     287                 :             : 
     288                 :          44 :   auto crate_num = mappings->get_current_crate ();
     289                 :          44 :   Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
     290                 :          44 :                                  mappings->get_next_hir_id (crate_num),
     291                 :          44 :                                  UNKNOWN_LOCAL_DEFID);
     292                 :             : 
     293                 :          44 :   translated
     294                 :          44 :     = new HIR::StructExprFieldIndexValue (mapping, field.get_index (),
     295                 :          44 :                                           std::unique_ptr<HIR::Expr> (value),
     296                 :          44 :                                           field.get_locus ());
     297                 :          44 : }
     298                 :             : 
     299                 :             : void
     300                 :         211 : ASTLowerStructExprField::visit (AST::StructExprFieldIdentifier &field)
     301                 :             : {
     302                 :         211 :   auto crate_num = mappings->get_current_crate ();
     303                 :         211 :   Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
     304                 :         211 :                                  mappings->get_next_hir_id (crate_num),
     305                 :         211 :                                  UNKNOWN_LOCAL_DEFID);
     306                 :             : 
     307                 :         211 :   translated
     308                 :         211 :     = new HIR::StructExprFieldIdentifier (mapping, field.get_field_name (),
     309                 :         422 :                                           field.get_locus ());
     310                 :         211 : }
     311                 :             : 
     312                 :             : // rust-ast-lower-block.h
     313                 :             : 
     314                 :             : void
     315                 :          35 : ASTLoweringExprWithBlock::visit (AST::WhileLoopExpr &expr)
     316                 :             : {
     317                 :          35 :   HIR::BlockExpr *loop_block
     318                 :          35 :     = ASTLoweringBlock::translate (expr.get_loop_block ().get (), &terminated);
     319                 :             : 
     320                 :          35 :   HIR::LoopLabel loop_label = lower_loop_label (expr.get_loop_label ());
     321                 :          35 :   HIR::Expr *loop_condition
     322                 :          35 :     = ASTLoweringExpr::translate (expr.get_predicate_expr ().get (),
     323                 :             :                                   &terminated);
     324                 :             : 
     325                 :          35 :   auto crate_num = mappings->get_current_crate ();
     326                 :          70 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     327                 :          35 :                                  mappings->get_next_hir_id (crate_num),
     328                 :          35 :                                  UNKNOWN_LOCAL_DEFID);
     329                 :             : 
     330                 :          35 :   translated
     331                 :          35 :     = new HIR::WhileLoopExpr (mapping,
     332                 :          35 :                               std::unique_ptr<HIR::Expr> (loop_condition),
     333                 :          70 :                               std::unique_ptr<HIR::BlockExpr> (loop_block),
     334                 :             :                               expr.get_locus (), std::move (loop_label),
     335                 :          70 :                               expr.get_outer_attrs ());
     336                 :          35 : }
     337                 :             : 
     338                 :             : void
     339                 :           0 : ASTLoweringExprWithBlock::visit (AST::ForLoopExpr &expr)
     340                 :             : {
     341                 :             :   // TODO FIXME
     342                 :             : 
     343                 :             :   // HIR::BlockExpr *loop_block
     344                 :             :   //   = ASTLoweringBlock::translate (expr.get_loop_block ().get (),
     345                 :             :   //   &terminated);
     346                 :             :   // HIR::LoopLabel loop_label = lower_loop_label (expr.get_loop_label ());
     347                 :             :   // HIR::Expr *iterator_expr
     348                 :             :   //   = ASTLoweringExpr::translate (expr.get_iterator_expr ().get (),
     349                 :             :   //                              &terminated);
     350                 :             :   // HIR::Pattern *loop_pattern
     351                 :             :   //   = ASTLoweringPattern::translate (expr.get_pattern ().get ());
     352                 :             : 
     353                 :             :   // auto crate_num = mappings->get_current_crate ();
     354                 :             :   // Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     355                 :             :   //                             mappings->get_next_hir_id (crate_num),
     356                 :             :   //                             UNKNOWN_LOCAL_DEFID);
     357                 :             : 
     358                 :           0 :   gcc_unreachable ();
     359                 :             : }
     360                 :             : 
     361                 :             : void
     362                 :         195 : ASTLoweringExprWithBlock::visit (AST::MatchExpr &expr)
     363                 :             : {
     364                 :         195 :   HIR::Expr *branch_value
     365                 :         195 :     = ASTLoweringExpr::translate (expr.get_scrutinee_expr ().get ());
     366                 :             : 
     367                 :         195 :   std::vector<HIR::MatchCase> match_arms;
     368                 :         686 :   for (auto &match_case : expr.get_match_cases ())
     369                 :             :     {
     370                 :         491 :       HIR::Expr *kase_expr
     371                 :         491 :         = ASTLoweringExpr::translate (match_case.get_expr ().get ());
     372                 :             : 
     373                 :         491 :       HIR::Expr *kase_guard_expr = nullptr;
     374                 :         491 :       if (match_case.get_arm ().has_match_arm_guard ())
     375                 :             :         {
     376                 :           1 :           kase_guard_expr = ASTLoweringExpr::translate (
     377                 :           1 :             match_case.get_arm ().get_guard_expr ().get ());
     378                 :             :         }
     379                 :             : 
     380                 :         491 :       std::vector<std::unique_ptr<HIR::Pattern>> match_arm_patterns;
     381                 :         982 :       for (auto &pattern : match_case.get_arm ().get_patterns ())
     382                 :             :         {
     383                 :         491 :           HIR::Pattern *ptrn = ASTLoweringPattern::translate (pattern.get ());
     384                 :         491 :           match_arm_patterns.push_back (std::unique_ptr<HIR::Pattern> (ptrn));
     385                 :             :         }
     386                 :             : 
     387                 :         491 :       HIR::MatchArm arm (std::move (match_arm_patterns), expr.get_locus (),
     388                 :         491 :                          std::unique_ptr<HIR::Expr> (kase_guard_expr),
     389                 :         491 :                          match_case.get_arm ().get_outer_attrs ());
     390                 :             : 
     391                 :         491 :       auto crate_num = mappings->get_current_crate ();
     392                 :         982 :       Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     393                 :         491 :                                      mappings->get_next_hir_id (crate_num),
     394                 :         491 :                                      UNKNOWN_LOCAL_DEFID);
     395                 :             : 
     396                 :         491 :       HIR::MatchCase kase (std::move (mapping), std::move (arm),
     397                 :         491 :                            std::unique_ptr<HIR::Expr> (kase_expr));
     398                 :         491 :       match_arms.push_back (std::move (kase));
     399                 :         491 :     }
     400                 :             : 
     401                 :         195 :   auto crate_num = mappings->get_current_crate ();
     402                 :         390 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     403                 :         195 :                                  mappings->get_next_hir_id (crate_num),
     404                 :         195 :                                  UNKNOWN_LOCAL_DEFID);
     405                 :             : 
     406                 :         195 :   translated
     407                 :         195 :     = new HIR::MatchExpr (mapping, std::unique_ptr<HIR::Expr> (branch_value),
     408                 :         195 :                           std::move (match_arms), expr.get_inner_attrs (),
     409                 :         390 :                           expr.get_outer_attrs (), expr.get_locus ());
     410                 :         195 : }
     411                 :             : 
     412                 :             : // rust-ast-lower-expr.h
     413                 :             : 
     414                 :             : void
     415                 :       11219 : ASTLowerPathInExpression::visit (AST::PathInExpression &expr)
     416                 :             : {
     417                 :       11219 :   std::vector<HIR::PathExprSegment> path_segments;
     418                 :       11219 :   auto &segments = expr.get_segments ();
     419                 :       24865 :   for (auto &s : segments)
     420                 :             :     {
     421                 :       13646 :       path_segments.push_back (lower_path_expr_seg ((s)));
     422                 :             : 
     423                 :             :       // insert the mappings for the segment
     424                 :       13646 :       HIR::PathExprSegment *lowered_seg = &path_segments.back ();
     425                 :       13646 :       mappings->insert_hir_path_expr_seg (lowered_seg);
     426                 :             :     }
     427                 :       11219 :   auto crate_num = mappings->get_current_crate ();
     428                 :       22438 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     429                 :       11219 :                                  mappings->get_next_hir_id (crate_num),
     430                 :       11219 :                                  UNKNOWN_LOCAL_DEFID);
     431                 :             : 
     432                 :       22438 :   translated = new HIR::PathInExpression (mapping, std::move (path_segments),
     433                 :             :                                           expr.get_locus (),
     434                 :       11219 :                                           expr.opening_scope_resolution ());
     435                 :       11219 : }
     436                 :             : 
     437                 :             : HIR::QualifiedPathType
     438                 :          80 : ASTLoweringBase::lower_qual_path_type (AST::QualifiedPathType &qualified_type)
     439                 :             : {
     440                 :          80 :   HIR::Type *type
     441                 :          80 :     = ASTLoweringType::translate (qualified_type.get_type ().get ());
     442                 :          80 :   HIR::TypePath *trait
     443                 :          80 :     = qualified_type.has_as_clause ()
     444                 :          80 :         ? ASTLowerTypePath::translate (qualified_type.get_as_type_path ())
     445                 :          80 :         : nullptr;
     446                 :             : 
     447                 :          80 :   auto crate_num = mappings->get_current_crate ();
     448                 :          80 :   Analysis::NodeMapping mapping (crate_num, qualified_type.get_node_id (),
     449                 :          80 :                                  mappings->get_next_hir_id (crate_num),
     450                 :          80 :                                  UNKNOWN_LOCAL_DEFID);
     451                 :             : 
     452                 :          80 :   return HIR::QualifiedPathType (mapping, std::unique_ptr<HIR::Type> (type),
     453                 :          80 :                                  std::unique_ptr<HIR::TypePath> (trait),
     454                 :          80 :                                  qualified_type.get_locus ());
     455                 :             : }
     456                 :             : 
     457                 :             : void
     458                 :          80 : ASTLowerQualPathInExpression::visit (AST::QualifiedPathInExpression &expr)
     459                 :             : {
     460                 :          80 :   HIR::QualifiedPathType qual_path_type
     461                 :          80 :     = lower_qual_path_type (expr.get_qualified_path_type ());
     462                 :             : 
     463                 :          80 :   std::vector<HIR::PathExprSegment> path_segments;
     464                 :          80 :   auto &segments = expr.get_segments ();
     465                 :         160 :   for (auto &s : segments)
     466                 :             :     {
     467                 :          80 :       path_segments.push_back (lower_path_expr_seg ((s)));
     468                 :             : 
     469                 :             :       // insert the mappings for the segment
     470                 :          80 :       HIR::PathExprSegment *lowered_seg = &path_segments.back ();
     471                 :          80 :       mappings->insert_hir_path_expr_seg (lowered_seg);
     472                 :             :     }
     473                 :             : 
     474                 :          80 :   auto crate_num = mappings->get_current_crate ();
     475                 :         160 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     476                 :          80 :                                  mappings->get_next_hir_id (crate_num),
     477                 :          80 :                                  UNKNOWN_LOCAL_DEFID);
     478                 :             : 
     479                 :          80 :   translated = new HIR::QualifiedPathInExpression (mapping, qual_path_type,
     480                 :             :                                                    std::move (path_segments),
     481                 :             :                                                    expr.get_locus (),
     482                 :         160 :                                                    expr.get_outer_attrs ());
     483                 :          80 : }
     484                 :             : 
     485                 :             : ClosureParam
     486                 :          53 : ASTLoweringBase::lower_closure_param (AST::ClosureParam &param)
     487                 :             : {
     488                 :          53 :   HIR::Pattern *param_pattern
     489                 :          53 :     = ASTLoweringPattern::translate (param.get_pattern ().get ());
     490                 :             : 
     491                 :          53 :   HIR::Type *param_type
     492                 :          53 :     = param.has_type_given ()
     493                 :          53 :         ? ASTLoweringType::translate (param.get_type ().get ())
     494                 :          53 :         : nullptr;
     495                 :             : 
     496                 :         106 :   return HIR::ClosureParam (std::unique_ptr<HIR::Pattern> (param_pattern),
     497                 :             :                             param.get_locus (),
     498                 :          53 :                             param.has_type_given ()
     499                 :         106 :                               ? std::unique_ptr<HIR::Type> (param_type)
     500                 :             :                               : nullptr,
     501                 :         159 :                             param.get_outer_attrs ());
     502                 :             : }
     503                 :             : 
     504                 :             : } // namespace HIR
     505                 :             : } // 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.