LCOV - code coverage report
Current view: top level - gcc/rust/backend - rust-compile-stmt.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 97.1 % 34 33
Test Date: 2024-04-20 14:03:02 Functions: 100.0 % 4 4
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-compile-pattern.h"
      20                 :             : #include "rust-compile-stmt.h"
      21                 :             : #include "rust-compile-expr.h"
      22                 :             : #include "rust-compile-type.h"
      23                 :             : #include "rust-compile-var-decl.h"
      24                 :             : 
      25                 :             : namespace Rust {
      26                 :             : namespace Compile {
      27                 :             : 
      28                 :       15433 : CompileStmt::CompileStmt (Context *ctx)
      29                 :       15433 :   : HIRCompileBase (ctx), translated (nullptr)
      30                 :       15433 : {}
      31                 :             : 
      32                 :             : tree
      33                 :       15433 : CompileStmt::Compile (HIR::Stmt *stmt, Context *ctx)
      34                 :             : {
      35                 :       15433 :   CompileStmt compiler (ctx);
      36                 :       15433 :   stmt->accept_vis (compiler);
      37                 :       15433 :   return compiler.translated;
      38                 :       15433 : }
      39                 :             : 
      40                 :             : void
      41                 :        5616 : CompileStmt::visit (HIR::ExprStmt &stmt)
      42                 :             : {
      43                 :        5616 :   translated = CompileExpr::Compile (stmt.get_expr ().get (), ctx);
      44                 :        5616 : }
      45                 :             : 
      46                 :             : void
      47                 :        9517 : CompileStmt::visit (HIR::LetStmt &stmt)
      48                 :             : {
      49                 :        9517 :   HIR::Pattern &stmt_pattern = *stmt.get_pattern ();
      50                 :        9517 :   HirId stmt_id = stmt_pattern.get_mappings ().get_hirid ();
      51                 :             : 
      52                 :        9517 :   TyTy::BaseType *ty = nullptr;
      53                 :        9517 :   if (!ctx->get_tyctx ()->lookup_type (stmt_id, &ty))
      54                 :             :     {
      55                 :             :       // FIXME this should be an assertion instead
      56                 :           0 :       rust_fatal_error (stmt.get_locus (),
      57                 :             :                         "failed to lookup variable declaration type");
      58                 :        1006 :       return;
      59                 :             :     }
      60                 :             : 
      61                 :             :   // setup var decl nodes
      62                 :        9517 :   fncontext fnctx = ctx->peek_fn ();
      63                 :        9517 :   tree fndecl = fnctx.fndecl;
      64                 :        9517 :   tree translated_type = TyTyResolveCompile::compile (ctx, ty);
      65                 :        9517 :   CompileVarDecl::compile (fndecl, translated_type, &stmt_pattern, ctx);
      66                 :             : 
      67                 :             :   // nothing to do
      68                 :        9517 :   if (!stmt.has_init_expr ())
      69                 :             :     return;
      70                 :             : 
      71                 :        8511 :   tree init = CompileExpr::Compile (stmt.get_init_expr ().get (), ctx);
      72                 :             :   // FIXME use error_mark_node, check that CompileExpr returns error_mark_node
      73                 :             :   // on failure and make this an assertion
      74                 :        8511 :   if (init == nullptr)
      75                 :             :     return;
      76                 :             : 
      77                 :        8511 :   TyTy::BaseType *actual = nullptr;
      78                 :        8511 :   bool ok = ctx->get_tyctx ()->lookup_type (
      79                 :        8511 :     stmt.get_init_expr ()->get_mappings ().get_hirid (), &actual);
      80                 :        8511 :   rust_assert (ok);
      81                 :             : 
      82                 :        8511 :   location_t lvalue_locus = stmt.get_pattern ()->get_locus ();
      83                 :        8511 :   location_t rvalue_locus = stmt.get_init_expr ()->get_locus ();
      84                 :        8511 :   TyTy::BaseType *expected = ty;
      85                 :        8511 :   init = coercion_site (stmt.get_mappings ().get_hirid (), init, actual,
      86                 :             :                         expected, lvalue_locus, rvalue_locus);
      87                 :             : 
      88                 :        8511 :   CompilePatternLet::Compile (&stmt_pattern, init, ty, rvalue_locus, ctx);
      89                 :             : }
      90                 :             : 
      91                 :             : } // namespace Compile
      92                 :             : } // 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.