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-02-28 14:20:25 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        22393 : ASTLoweringStmt::translate (AST::Stmt *stmt, bool *terminated)
      31              : {
      32        22393 :   ASTLoweringStmt resolver;
      33        22393 :   stmt->accept_vis (resolver);
      34              : 
      35        22393 :   if (!resolver.translated)
      36              :     return nullptr;
      37              : 
      38        22384 :   *terminated = resolver.terminated;
      39        22384 :   resolver.mappings.insert_location (
      40        22384 :     resolver.translated->get_mappings ().get_hirid (),
      41        22384 :     resolver.translated->get_locus ());
      42        22384 :   resolver.mappings.insert_hir_stmt (resolver.translated);
      43              : 
      44        22384 :   return resolver.translated;
      45        22393 : }
      46              : 
      47              : void
      48         9260 : ASTLoweringStmt::visit (AST::ExprStmt &stmt)
      49              : {
      50         9260 :   HIR::Expr *expr = ASTLoweringExpr::translate (stmt.get_expr (), &terminated);
      51              : 
      52         9260 :   auto crate_num = mappings.get_current_crate ();
      53        18520 :   Analysis::NodeMapping mapping (crate_num, stmt.get_node_id (),
      54         9260 :                                  mappings.get_next_hir_id (crate_num),
      55         9260 :                                  UNKNOWN_LOCAL_DEFID);
      56         9260 :   translated
      57         9260 :     = new HIR::ExprStmt (mapping, std::unique_ptr<HIR::Expr> (expr),
      58         9260 :                          stmt.get_locus (), !stmt.is_semicolon_followed ());
      59         9260 : }
      60              : 
      61              : void
      62           54 : ASTLoweringStmt::visit (AST::ConstantItem &constant)
      63              : {
      64           54 :   translated = ASTLoweringItem::translate (constant);
      65           54 : }
      66              : 
      67              : void
      68        12650 : ASTLoweringStmt::visit (AST::LetStmt &stmt)
      69              : {
      70        12650 :   HIR::Pattern *variables
      71        12650 :     = ASTLoweringPattern::translate (stmt.get_pattern (), true);
      72              : 
      73        12650 :   tl::optional<std::unique_ptr<Type>> type = tl::nullopt;
      74              : 
      75        12650 :   if (stmt.has_type ())
      76         2090 :     type
      77         2090 :       = std::unique_ptr<Type> (ASTLoweringType::translate (stmt.get_type ()));
      78              : 
      79        12650 :   tl::optional<std::unique_ptr<HIR::Expr>> init_expr = tl::nullopt;
      80        12650 :   tl::optional<std::unique_ptr<HIR::Expr>> else_expr = tl::nullopt;
      81              : 
      82        12650 :   if (stmt.has_init_expr ())
      83        11510 :     init_expr = std::unique_ptr<HIR::Expr> (
      84        11510 :       ASTLoweringExpr::translate (stmt.get_init_expr ()));
      85              : 
      86        12650 :   if (stmt.has_else_expr ())
      87            5 :     else_expr = std::unique_ptr<HIR::Expr> (
      88            5 :       ASTLoweringExpr::translate (stmt.get_else_expr ()));
      89              : 
      90        12650 :   auto crate_num = mappings.get_current_crate ();
      91        25300 :   Analysis::NodeMapping mapping (crate_num, stmt.get_node_id (),
      92        12650 :                                  mappings.get_next_hir_id (crate_num),
      93        12650 :                                  UNKNOWN_LOCAL_DEFID);
      94        12650 :   translated
      95        12650 :     = new HIR::LetStmt (mapping, std::unique_ptr<HIR::Pattern> (variables),
      96              :                         std::move (init_expr), std::move (else_expr),
      97        12650 :                         std::move (type), stmt.get_outer_attrs (),
      98        65345 :                         stmt.get_locus ());
      99        24160 : }
     100              : 
     101              : void
     102          136 : ASTLoweringStmt::visit (AST::TupleStruct &struct_decl)
     103              : {
     104          136 :   translated = ASTLoweringItem::translate (struct_decl);
     105          136 : }
     106              : 
     107              : void
     108          132 : ASTLoweringStmt::visit (AST::StructStruct &struct_decl)
     109              : {
     110          132 :   translated = ASTLoweringItem::translate (struct_decl);
     111          132 : }
     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           10 : ASTLoweringStmt::visit (AST::Enum &enum_decl)
     121              : {
     122           10 :   translated = ASTLoweringItem::translate (enum_decl);
     123           10 : }
     124              : 
     125              : void
     126           46 : ASTLoweringStmt::visit (AST::EmptyStmt &empty)
     127              : {
     128           46 :   auto crate_num = mappings.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           65 : ASTLoweringStmt::visit (AST::Function &function)
     138              : {
     139           65 :   translated = ASTLoweringItem::translate (function);
     140           65 : }
     141              : 
     142              : void
     143           16 : ASTLoweringStmt::visit (AST::ExternBlock &extern_block)
     144              : {
     145           16 :   translated = lower_extern_block (extern_block);
     146           16 : }
     147              : 
     148              : void
     149            5 : ASTLoweringStmt::visit (AST::MacroRulesDefinition &def)
     150              : {
     151            5 :   lower_macro_definition (def);
     152            5 : }
     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            6 : ASTLoweringStmt::visit (AST::TraitImpl &impl_block)
     168              : {
     169            6 :   translated = ASTLoweringItem::translate (impl_block);
     170            6 : }
     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.4-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.