LCOV - code coverage report
Current view: top level - gcc/rust/backend - rust-compile-implitem.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 50.0 % 40 20
Test Date: 2024-04-20 14:03:02 Functions: 50.0 % 2 1
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-implitem.h"
      20                 :             : 
      21                 :             : namespace Rust {
      22                 :             : namespace Compile {
      23                 :             : 
      24                 :             : void
      25                 :           0 : CompileTraitItem::visit (HIR::TraitItemConst &constant)
      26                 :             : {
      27                 :           0 :   rust_assert (concrete != nullptr);
      28                 :           0 :   TyTy::BaseType *resolved_type = concrete;
      29                 :             : 
      30                 :           0 :   const Resolver::CanonicalPath *canonical_path = nullptr;
      31                 :           0 :   bool ok = ctx->get_mappings ()->lookup_canonical_path (
      32                 :           0 :     constant.get_mappings ().get_nodeid (), &canonical_path);
      33                 :           0 :   rust_assert (ok);
      34                 :             : 
      35                 :           0 :   HIR::Expr *const_value_expr = constant.get_expr ().get ();
      36                 :           0 :   tree const_expr
      37                 :           0 :     = compile_constant_item (resolved_type, canonical_path, const_value_expr,
      38                 :             :                              constant.get_locus ());
      39                 :           0 :   ctx->push_const (const_expr);
      40                 :           0 :   ctx->insert_const_decl (constant.get_mappings ().get_hirid (), const_expr);
      41                 :             : 
      42                 :           0 :   reference = const_expr;
      43                 :           0 : }
      44                 :             : 
      45                 :             : void
      46                 :         123 : CompileTraitItem::visit (HIR::TraitItemFunc &func)
      47                 :             : {
      48                 :         123 :   rust_assert (func.has_block_defined ());
      49                 :             : 
      50                 :         123 :   rust_assert (concrete->get_kind () == TyTy::TypeKind::FNDEF);
      51                 :         123 :   TyTy::FnType *fntype = static_cast<TyTy::FnType *> (concrete);
      52                 :         123 :   fntype->monomorphize ();
      53                 :             : 
      54                 :             :   // items can be forward compiled which means we may not need to invoke this
      55                 :             :   // code. We might also have already compiled this generic function as well.
      56                 :         123 :   tree lookup = NULL_TREE;
      57                 :         123 :   if (ctx->lookup_function_decl (fntype->get_ty_ref (), &lookup,
      58                 :             :                                  fntype->get_id (), fntype))
      59                 :             :     {
      60                 :             :       // has this been added to the list then it must be finished
      61                 :           0 :       if (ctx->function_completed (lookup))
      62                 :             :         {
      63                 :           0 :           tree dummy = NULL_TREE;
      64                 :           0 :           if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &dummy))
      65                 :             :             {
      66                 :           0 :               ctx->insert_function_decl (fntype, lookup);
      67                 :             :             }
      68                 :             : 
      69                 :           0 :           reference = address_expression (lookup, ref_locus);
      70                 :           0 :           return;
      71                 :             :         }
      72                 :             :     }
      73                 :             : 
      74                 :         123 :   if (fntype->has_substitutions_defined ())
      75                 :             :     {
      76                 :             :       // override the Hir Lookups for the substituions in this context
      77                 :         123 :       fntype->override_context ();
      78                 :             :     }
      79                 :             : 
      80                 :         123 :   const Resolver::CanonicalPath *canonical_path = nullptr;
      81                 :         123 :   bool ok = ctx->get_mappings ()->lookup_canonical_path (
      82                 :         123 :     func.get_mappings ().get_nodeid (), &canonical_path);
      83                 :         123 :   rust_assert (ok);
      84                 :             : 
      85                 :             :   // FIXME: How do we get the proper visibility here?
      86                 :         123 :   auto vis = HIR::Visibility (HIR::Visibility::VisType::PUBLIC);
      87                 :         123 :   HIR::TraitFunctionDecl &function = func.get_decl ();
      88                 :         123 :   tree fndecl
      89                 :         123 :     = compile_function (function.get_function_name ().as_string (),
      90                 :             :                         function.get_self (), function.get_function_params (),
      91                 :             :                         function.get_qualifiers (), vis,
      92                 :             :                         func.get_outer_attrs (), func.get_locus (),
      93                 :         123 :                         func.get_block_expr ().get (), canonical_path, fntype);
      94                 :         123 :   reference = address_expression (fndecl, ref_locus);
      95                 :         123 : }
      96                 :             : 
      97                 :             : } // namespace Compile
      98                 :             : } // 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.