LCOV - code coverage report
Current view: top level - gcc/rust/hir - rust-ast-lower-block.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 93.3 % 89 83
Test Date: 2025-07-12 13:27:34 Functions: 55.6 % 18 10
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                 :             : #ifndef RUST_AST_LOWER_BLOCK
      20                 :             : #define RUST_AST_LOWER_BLOCK
      21                 :             : 
      22                 :             : #include "rust-diagnostics.h"
      23                 :             : #include "rust-ast-lower-base.h"
      24                 :             : 
      25                 :             : namespace Rust {
      26                 :             : namespace HIR {
      27                 :             : 
      28                 :       22594 : class ASTLoweringBlock : public ASTLoweringBase
      29                 :             : {
      30                 :             :   using Rust::HIR::ASTLoweringBase::visit;
      31                 :             : 
      32                 :             : public:
      33                 :       19160 :   static HIR::BlockExpr *translate (AST::BlockExpr &expr, bool *terminated)
      34                 :             :   {
      35                 :       38320 :     ASTLoweringBlock resolver;
      36                 :       19160 :     expr.normalize_tail_expr ();
      37                 :       19160 :     expr.accept_vis (resolver);
      38                 :       19160 :     if (resolver.translated != nullptr)
      39                 :             :       {
      40                 :       19160 :         resolver.mappings.insert_hir_expr (resolver.translated);
      41                 :             :       }
      42                 :             : 
      43                 :       19160 :     *terminated = resolver.terminated;
      44                 :       19160 :     return resolver.translated;
      45                 :       19160 :   }
      46                 :             : 
      47                 :        3434 :   static HIR::UnsafeBlockExpr *translate (AST::UnsafeBlockExpr &expr,
      48                 :             :                                           bool *terminated)
      49                 :             :   {
      50                 :        6868 :     ASTLoweringBlock resolver;
      51                 :             : 
      52                 :        3434 :     HIR::BlockExpr *block
      53                 :        3434 :       = ASTLoweringBlock::translate (expr.get_block_expr (), terminated);
      54                 :        3434 :     auto crate_num = resolver.mappings.get_current_crate ();
      55                 :        6868 :     Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
      56                 :             :                                    resolver.mappings.get_next_hir_id (
      57                 :             :                                      crate_num),
      58                 :        3434 :                                    UNKNOWN_LOCAL_DEFID);
      59                 :             : 
      60                 :        3434 :     HIR::UnsafeBlockExpr *translated
      61                 :             :       = new HIR::UnsafeBlockExpr (mapping,
      62                 :        3434 :                                   std::unique_ptr<HIR::BlockExpr> (block),
      63                 :        3434 :                                   expr.get_outer_attrs (), expr.get_locus ());
      64                 :             : 
      65                 :        3434 :     resolver.mappings.insert_hir_expr (translated);
      66                 :             : 
      67                 :        3434 :     return translated;
      68                 :        3434 :   }
      69                 :             : 
      70                 :             :   void visit (AST::BlockExpr &expr) override;
      71                 :             : 
      72                 :             : private:
      73                 :       22594 :   ASTLoweringBlock ()
      74                 :       22594 :     : ASTLoweringBase (), translated (nullptr), terminated (false)
      75                 :             :   {}
      76                 :             : 
      77                 :             :   HIR::BlockExpr *translated;
      78                 :             :   bool terminated;
      79                 :             : };
      80                 :             : 
      81                 :             : class ASTLoweringIfBlock : public ASTLoweringBase
      82                 :             : {
      83                 :             :   using Rust::HIR::ASTLoweringBase::visit;
      84                 :             : 
      85                 :             : public:
      86                 :         974 :   static HIR::IfExpr *translate (AST::IfExpr &expr, bool *terminated)
      87                 :             :   {
      88                 :        1948 :     ASTLoweringIfBlock resolver;
      89                 :         974 :     expr.accept_vis (resolver);
      90                 :         974 :     if (resolver.translated != nullptr)
      91                 :             :       {
      92                 :         974 :         resolver.mappings.insert_hir_expr (resolver.translated);
      93                 :             :       }
      94                 :         974 :     *terminated = resolver.terminated;
      95                 :         974 :     return resolver.translated;
      96                 :         974 :   }
      97                 :             : 
      98                 :         974 :   ~ASTLoweringIfBlock () {}
      99                 :             : 
     100                 :             :   void visit (AST::IfExpr &expr) override;
     101                 :             : 
     102                 :             :   void visit (AST::IfExprConseqElse &expr) override;
     103                 :             : 
     104                 :             : private:
     105                 :         974 :   ASTLoweringIfBlock ()
     106                 :         974 :     : ASTLoweringBase (), translated (nullptr), terminated (false)
     107                 :             :   {}
     108                 :             : 
     109                 :             :   HIR::IfExpr *translated;
     110                 :             :   bool terminated;
     111                 :             : };
     112                 :             : 
     113                 :             : class ASTLoweringIfLetBlock : public ASTLoweringBase
     114                 :             : {
     115                 :             :   using Rust::HIR::ASTLoweringBase::visit;
     116                 :             : 
     117                 :             : public:
     118                 :          34 :   static HIR::MatchExpr *translate (AST::IfLetExpr &expr)
     119                 :             :   {
     120                 :          68 :     ASTLoweringIfLetBlock resolver;
     121                 :          34 :     expr.accept_vis (resolver);
     122                 :          34 :     if (resolver.translated != nullptr)
     123                 :             :       {
     124                 :          34 :         resolver.mappings.insert_hir_expr (resolver.translated);
     125                 :             :       }
     126                 :          34 :     return resolver.translated;
     127                 :          34 :   }
     128                 :             : 
     129                 :          34 :   ~ASTLoweringIfLetBlock () {}
     130                 :             : 
     131                 :             :   void visit (AST::IfLetExpr &expr) override;
     132                 :             : 
     133                 :             :   void visit (AST::IfLetExprConseqElse &expr) override;
     134                 :             : 
     135                 :             : private:
     136                 :          34 :   ASTLoweringIfLetBlock () : ASTLoweringBase (), translated (nullptr) {}
     137                 :             : 
     138                 :             :   void desugar_iflet (AST::IfLetExpr &, HIR::Expr **, HIR::Expr *,
     139                 :             :                       std::vector<HIR::MatchCase> &);
     140                 :             : 
     141                 :             :   HIR::MatchExpr *translated;
     142                 :             : };
     143                 :             : 
     144                 :             : class ASTLoweringExprWithBlock : public ASTLoweringBase
     145                 :             : {
     146                 :             :   using Rust::HIR::ASTLoweringBase::visit;
     147                 :             : 
     148                 :             : public:
     149                 :        1242 :   static HIR::ExprWithBlock *translate (AST::ExprWithBlock &expr,
     150                 :             :                                         bool *terminated)
     151                 :             :   {
     152                 :        2484 :     ASTLoweringExprWithBlock resolver;
     153                 :        1242 :     expr.accept_vis (resolver);
     154                 :        1242 :     if (resolver.translated != nullptr)
     155                 :        1242 :       resolver.mappings.insert_hir_expr (resolver.translated);
     156                 :             : 
     157                 :        1242 :     *terminated = resolver.terminated;
     158                 :        1242 :     return resolver.translated;
     159                 :        1242 :   }
     160                 :             : 
     161                 :        1242 :   ~ASTLoweringExprWithBlock () {}
     162                 :             : 
     163                 :          12 :   void visit (AST::IfExpr &expr) override
     164                 :             :   {
     165                 :          12 :     translated = ASTLoweringIfBlock::translate (expr, &terminated);
     166                 :          12 :   }
     167                 :             : 
     168                 :          34 :   void visit (AST::IfExprConseqElse &expr) override
     169                 :             :   {
     170                 :          34 :     translated = ASTLoweringIfBlock::translate (expr, &terminated);
     171                 :          34 :   }
     172                 :             : 
     173                 :           0 :   void visit (AST::IfLetExpr &expr) override
     174                 :             :   {
     175                 :           0 :     translated = ASTLoweringIfLetBlock::translate (expr);
     176                 :           0 :   }
     177                 :             : 
     178                 :           2 :   void visit (AST::IfLetExprConseqElse &expr) override
     179                 :             :   {
     180                 :           2 :     translated = ASTLoweringIfLetBlock::translate (expr);
     181                 :           2 :   }
     182                 :             : 
     183                 :         527 :   void visit (AST::BlockExpr &expr) override
     184                 :             :   {
     185                 :         527 :     translated = ASTLoweringBlock::translate (expr, &terminated);
     186                 :         527 :   }
     187                 :             : 
     188                 :           0 :   void visit (AST::UnsafeBlockExpr &expr) override
     189                 :             :   {
     190                 :           0 :     translated = ASTLoweringBlock::translate (expr, &terminated);
     191                 :           0 :   }
     192                 :             : 
     193                 :         124 :   void visit (AST::LoopExpr &expr) override
     194                 :             :   {
     195                 :         124 :     HIR::BlockExpr *loop_block
     196                 :         124 :       = ASTLoweringBlock::translate (expr.get_loop_block (), &terminated);
     197                 :             : 
     198                 :         124 :     tl::optional<HIR::LoopLabel> loop_label = tl::nullopt;
     199                 :         124 :     if (expr.has_loop_label ())
     200                 :          32 :       loop_label = lower_loop_label (expr.get_loop_label ());
     201                 :             : 
     202                 :         124 :     auto crate_num = mappings.get_current_crate ();
     203                 :         248 :     Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     204                 :         124 :                                    mappings.get_next_hir_id (crate_num),
     205                 :         124 :                                    UNKNOWN_LOCAL_DEFID);
     206                 :             : 
     207                 :         124 :     translated
     208                 :         124 :       = new HIR::LoopExpr (mapping,
     209                 :         124 :                            std::unique_ptr<HIR::BlockExpr> (loop_block),
     210                 :             :                            expr.get_locus (), std::move (loop_label),
     211                 :         248 :                            expr.get_outer_attrs ());
     212                 :         124 :   }
     213                 :             : 
     214                 :             :   void visit (AST::WhileLoopExpr &expr) override;
     215                 :             : 
     216                 :             :   void visit (AST::ForLoopExpr &expr) override;
     217                 :             : 
     218                 :             :   void visit (AST::MatchExpr &expr) override;
     219                 :             : 
     220                 :             : private:
     221                 :        1242 :   ASTLoweringExprWithBlock ()
     222                 :        1242 :     : ASTLoweringBase (), translated (nullptr), terminated (false)
     223                 :             :   {}
     224                 :             : 
     225                 :             :   HIR::ExprWithBlock *translated;
     226                 :             :   bool terminated;
     227                 :             : };
     228                 :             : 
     229                 :             : } // namespace HIR
     230                 :             : } // namespace Rust
     231                 :             : 
     232                 :             : #endif // RUST_AST_LOWER_BLOCK
        

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.