LCOV - code coverage report
Current view: top level - gcc/rust/hir - rust-ast-lower-stmt.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 97.7 % 88 86
Test Date: 2025-04-12 15:46:39 Functions: 100.0 % 16 16
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 "optional.h"
      20                 :             : #include "rust-ast-lower-item.h"
      21                 :             : #include "rust-ast-lower-stmt.h"
      22                 :             : #include "rust-ast-lower-type.h"
      23                 :             : #include "rust-ast-lower-expr.h"
      24                 :             : #include "rust-ast-lower-pattern.h"
      25                 :             : 
      26                 :             : namespace Rust {
      27                 :             : namespace HIR {
      28                 :             : 
      29                 :             : HIR::Stmt *
      30                 :       22448 : ASTLoweringStmt::translate (AST::Stmt *stmt, bool *terminated)
      31                 :             : {
      32                 :       22448 :   ASTLoweringStmt resolver;
      33                 :       22448 :   stmt->accept_vis (resolver);
      34                 :             : 
      35                 :       22448 :   if (!resolver.translated)
      36                 :             :     return nullptr;
      37                 :             : 
      38                 :       22439 :   *terminated = resolver.terminated;
      39                 :       22439 :   resolver.mappings.insert_location (
      40                 :       22439 :     resolver.translated->get_mappings ().get_hirid (),
      41                 :       22439 :     resolver.translated->get_locus ());
      42                 :       22439 :   resolver.mappings.insert_hir_stmt (resolver.translated);
      43                 :             : 
      44                 :       22439 :   return resolver.translated;
      45                 :       22448 : }
      46                 :             : 
      47                 :             : void
      48                 :        8250 : ASTLoweringStmt::visit (AST::ExprStmt &stmt)
      49                 :             : {
      50                 :        8250 :   HIR::Expr *expr = ASTLoweringExpr::translate (stmt.get_expr (), &terminated);
      51                 :             : 
      52                 :        8250 :   auto crate_num = mappings.get_current_crate ();
      53                 :        8250 :   Analysis::NodeMapping mapping (crate_num, stmt.get_node_id (),
      54                 :        8250 :                                  mappings.get_next_hir_id (crate_num),
      55                 :        8250 :                                  UNKNOWN_LOCAL_DEFID);
      56                 :        8250 :   translated
      57                 :        8250 :     = new HIR::ExprStmt (mapping, std::unique_ptr<HIR::Expr> (expr),
      58                 :        8250 :                          stmt.get_locus (), !stmt.is_semicolon_followed ());
      59                 :        8250 : }
      60                 :             : 
      61                 :             : void
      62                 :          74 : ASTLoweringStmt::visit (AST::ConstantItem &constant)
      63                 :             : {
      64                 :          74 :   translated = ASTLoweringItem::translate (constant);
      65                 :          74 : }
      66                 :             : 
      67                 :             : void
      68                 :       13682 : ASTLoweringStmt::visit (AST::LetStmt &stmt)
      69                 :             : {
      70                 :       13682 :   HIR::Pattern *variables
      71                 :       13682 :     = ASTLoweringPattern::translate (stmt.get_pattern (), true);
      72                 :             : 
      73                 :       13682 :   tl::optional<std::unique_ptr<Type>> type = tl::nullopt;
      74                 :             : 
      75                 :       13682 :   if (stmt.has_type ())
      76                 :        2351 :     type
      77                 :        2351 :       = std::unique_ptr<Type> (ASTLoweringType::translate (stmt.get_type ()));
      78                 :             : 
      79                 :       13682 :   tl::optional<std::unique_ptr<HIR::Expr>> init_expr = tl::nullopt;
      80                 :       13682 :   tl::optional<std::unique_ptr<HIR::Expr>> else_expr = tl::nullopt;
      81                 :             : 
      82                 :       13682 :   if (stmt.has_init_expr ())
      83                 :       12414 :     init_expr = std::unique_ptr<HIR::Expr> (
      84                 :       12414 :       ASTLoweringExpr::translate (stmt.get_init_expr ()));
      85                 :             : 
      86                 :       13682 :   if (stmt.has_else_expr ())
      87                 :           0 :     else_expr = std::unique_ptr<HIR::Expr> (
      88                 :           0 :       ASTLoweringExpr::translate (stmt.get_else_expr ()));
      89                 :             : 
      90                 :       13682 :   auto crate_num = mappings.get_current_crate ();
      91                 :       13682 :   Analysis::NodeMapping mapping (crate_num, stmt.get_node_id (),
      92                 :       13682 :                                  mappings.get_next_hir_id (crate_num),
      93                 :       13682 :                                  UNKNOWN_LOCAL_DEFID);
      94                 :       13682 :   translated
      95                 :       13682 :     = new HIR::LetStmt (mapping, std::unique_ptr<HIR::Pattern> (variables),
      96                 :             :                         std::move (init_expr), std::move (else_expr),
      97                 :       13682 :                         std::move (type), stmt.get_outer_attrs (),
      98                 :       70761 :                         stmt.get_locus ());
      99                 :       26096 : }
     100                 :             : 
     101                 :             : void
     102                 :         134 : ASTLoweringStmt::visit (AST::TupleStruct &struct_decl)
     103                 :             : {
     104                 :         134 :   translated = ASTLoweringItem::translate (struct_decl);
     105                 :         134 : }
     106                 :             : 
     107                 :             : void
     108                 :         101 : ASTLoweringStmt::visit (AST::StructStruct &struct_decl)
     109                 :             : {
     110                 :         101 :   translated = ASTLoweringItem::translate (struct_decl);
     111                 :         101 : }
     112                 :             : 
     113                 :             : void
     114                 :           2 : ASTLoweringStmt::visit (AST::Union &union_decl)
     115                 :             : {
     116                 :           2 :   translated = ASTLoweringItem::translate (union_decl);
     117                 :           2 : }
     118                 :             : 
     119                 :             : void
     120                 :          18 : ASTLoweringStmt::visit (AST::Enum &enum_decl)
     121                 :             : {
     122                 :          18 :   translated = ASTLoweringItem::translate (enum_decl);
     123                 :          18 : }
     124                 :             : 
     125                 :             : void
     126                 :          54 : ASTLoweringStmt::visit (AST::EmptyStmt &empty)
     127                 :             : {
     128                 :          54 :   auto crate_num = mappings.get_current_crate ();
     129                 :          54 :   Analysis::NodeMapping mapping (crate_num, empty.get_node_id (),
     130                 :          54 :                                  mappings.get_next_hir_id (crate_num),
     131                 :          54 :                                  mappings.get_next_localdef_id (crate_num));
     132                 :             : 
     133                 :          54 :   translated = new HIR::EmptyStmt (mapping, empty.get_locus ());
     134                 :          54 : }
     135                 :             : 
     136                 :             : void
     137                 :          83 : ASTLoweringStmt::visit (AST::Function &function)
     138                 :             : {
     139                 :          83 :   translated = ASTLoweringItem::translate (function);
     140                 :          83 : }
     141                 :             : 
     142                 :             : void
     143                 :          18 : ASTLoweringStmt::visit (AST::ExternBlock &extern_block)
     144                 :             : {
     145                 :          18 :   translated = lower_extern_block (extern_block);
     146                 :          18 : }
     147                 :             : 
     148                 :             : void
     149                 :           7 : ASTLoweringStmt::visit (AST::MacroRulesDefinition &def)
     150                 :             : {
     151                 :           7 :   lower_macro_definition (def);
     152                 :           7 : }
     153                 :             : 
     154                 :             : void
     155                 :          11 : ASTLoweringStmt::visit (AST::Trait &trait)
     156                 :             : {
     157                 :          11 :   translated = ASTLoweringItem::translate (trait);
     158                 :          11 : }
     159                 :             : 
     160                 :             : void
     161                 :           2 : ASTLoweringStmt::visit (AST::InherentImpl &impl_block)
     162                 :             : {
     163                 :           2 :   translated = ASTLoweringItem::translate (impl_block);
     164                 :           2 : }
     165                 :             : 
     166                 :             : void
     167                 :           9 : ASTLoweringStmt::visit (AST::TraitImpl &impl_block)
     168                 :             : {
     169                 :           9 :   translated = ASTLoweringItem::translate (impl_block);
     170                 :           9 : }
     171                 :             : 
     172                 :             : void
     173                 :           1 : ASTLoweringStmt::visit (AST::StaticItem &var)
     174                 :             : {
     175                 :           1 :   translated = ASTLoweringItem::translate (var);
     176                 :           1 : }
     177                 :             : 
     178                 :             : } // namespace HIR
     179                 :             : } // 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.