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: 100.0 % 88 88
Test Date: 2026-12-05 16:10:02 Functions: 100.0 % 16 16
Legend: Lines:     hit not hit

            Line data    Source code
       1              : // Copyright (C) 2020-2026 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       139225 : ASTLoweringStmt::translate (AST::Stmt *stmt, bool *terminated)
      31              : {
      32       139225 :   ASTLoweringStmt resolver;
      33       139225 :   stmt->accept_vis (resolver);
      34              : 
      35       139225 :   if (!resolver.translated)
      36              :     return nullptr;
      37              : 
      38       132654 :   *terminated = resolver.terminated;
      39       132654 :   resolver.mappings.insert_location (
      40       132654 :     resolver.translated->get_mappings ().get_hirid (),
      41       132654 :     resolver.translated->get_locus ());
      42       132654 :   resolver.mappings.hir.stmts.insert (resolver.translated);
      43              : 
      44       132654 :   return resolver.translated;
      45       139225 : }
      46              : 
      47              : void
      48        63686 : ASTLoweringStmt::visit (AST::ExprStmt &stmt)
      49              : {
      50        63686 :   HIR::Expr *expr = ASTLoweringExpr::translate (stmt.get_expr (), &terminated);
      51              : 
      52        63686 :   auto crate_num = mappings.crate.get_current_crate ();
      53       127372 :   Analysis::NodeMapping mapping (crate_num, stmt.get_node_id (),
      54        63686 :                                  mappings.get_next_hir_id (crate_num),
      55        63686 :                                  UNKNOWN_LOCAL_DEFID);
      56        63686 :   translated
      57        63686 :     = new HIR::ExprStmt (mapping, std::unique_ptr<HIR::Expr> (expr),
      58        63686 :                          stmt.get_locus (), !stmt.is_semicolon_followed ());
      59        63686 : }
      60              : 
      61              : void
      62          459 : ASTLoweringStmt::visit (AST::ConstantItem &constant)
      63              : {
      64          459 :   translated = ASTLoweringItem::translate (constant);
      65          459 : }
      66              : 
      67              : void
      68        62214 : ASTLoweringStmt::visit (AST::LetStmt &stmt)
      69              : {
      70        62214 :   HIR::Pattern *variables
      71        62214 :     = ASTLoweringPattern::translate (stmt.get_pattern (), true);
      72              : 
      73        62214 :   tl::optional<std::unique_ptr<Type>> type = tl::nullopt;
      74              : 
      75        62214 :   if (stmt.has_type ())
      76         7186 :     type
      77         7186 :       = std::unique_ptr<Type> (ASTLoweringType::translate (stmt.get_type ()));
      78              : 
      79        62214 :   tl::optional<std::unique_ptr<HIR::Expr>> init_expr = tl::nullopt;
      80        62214 :   tl::optional<std::unique_ptr<HIR::Expr>> else_expr = tl::nullopt;
      81              : 
      82        62214 :   if (stmt.has_init_expr ())
      83        58390 :     init_expr = std::unique_ptr<HIR::Expr> (
      84        58390 :       ASTLoweringExpr::translate (stmt.get_init_expr ()));
      85              : 
      86        62214 :   if (stmt.has_else_expr ())
      87            5 :     else_expr = std::unique_ptr<HIR::Expr> (
      88            5 :       ASTLoweringExpr::translate (stmt.get_else_expr ()));
      89              : 
      90        62214 :   auto crate_num = mappings.crate.get_current_crate ();
      91       124428 :   Analysis::NodeMapping mapping (crate_num, stmt.get_node_id (),
      92        62214 :                                  mappings.get_next_hir_id (crate_num),
      93        62214 :                                  UNKNOWN_LOCAL_DEFID);
      94        62214 :   translated
      95        62214 :     = new HIR::LetStmt (mapping, std::unique_ptr<HIR::Pattern> (variables),
      96              :                         std::move (init_expr), std::move (else_expr),
      97        62214 :                         std::move (type), stmt.get_outer_attrs (),
      98       318261 :                         stmt.get_locus ());
      99       120604 : }
     100              : 
     101              : void
     102          199 : ASTLoweringStmt::visit (AST::TupleStruct &struct_decl)
     103              : {
     104          199 :   translated = ASTLoweringItem::translate (struct_decl);
     105          199 : }
     106              : 
     107              : void
     108         5032 : ASTLoweringStmt::visit (AST::StructStruct &struct_decl)
     109              : {
     110         5032 :   translated = ASTLoweringItem::translate (struct_decl);
     111         5032 : }
     112              : 
     113              : void
     114            1 : ASTLoweringStmt::visit (AST::Union &union_decl)
     115              : {
     116            1 :   translated = ASTLoweringItem::translate (union_decl);
     117            1 : }
     118              : 
     119              : void
     120           16 : ASTLoweringStmt::visit (AST::Enum &enum_decl)
     121              : {
     122           16 :   translated = ASTLoweringItem::translate (enum_decl);
     123           16 : }
     124              : 
     125              : void
     126           46 : ASTLoweringStmt::visit (AST::EmptyStmt &empty)
     127              : {
     128           46 :   auto crate_num = mappings.crate.get_current_crate ();
     129           92 :   Analysis::NodeMapping mapping (crate_num, empty.get_node_id (),
     130           46 :                                  mappings.get_next_hir_id (crate_num),
     131           46 :                                  mappings.get_next_localdef_id (crate_num));
     132              : 
     133           46 :   translated = new HIR::EmptyStmt (mapping, empty.get_locus ());
     134           46 : }
     135              : 
     136              : void
     137          856 : ASTLoweringStmt::visit (AST::Function &function)
     138              : {
     139          856 :   translated = ASTLoweringItem::translate (function);
     140          856 : }
     141              : 
     142              : void
     143           66 : ASTLoweringStmt::visit (AST::ExternBlock &extern_block)
     144              : {
     145           66 :   translated = lower_extern_block (extern_block);
     146           66 : }
     147              : 
     148              : void
     149         6114 : ASTLoweringStmt::visit (AST::MacroRulesDefinition &def)
     150              : {
     151         6114 :   lower_macro_definition (def);
     152         6114 : }
     153              : 
     154              : void
     155            6 : ASTLoweringStmt::visit (AST::Trait &trait)
     156              : {
     157            6 :   translated = ASTLoweringItem::translate (trait);
     158            6 : }
     159              : 
     160              : void
     161            1 : ASTLoweringStmt::visit (AST::InherentImpl &impl_block)
     162              : {
     163            1 :   translated = ASTLoweringItem::translate (impl_block);
     164            1 : }
     165              : 
     166              : void
     167           71 : ASTLoweringStmt::visit (AST::TraitImpl &impl_block)
     168              : {
     169           71 :   translated = ASTLoweringItem::translate (impl_block);
     170           71 : }
     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.6-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.