LCOV - code coverage report
Current view: top level - gcc/rust/ast - rust-collect-lang-items.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 100.0 % 54 54
Test Date: 2026-12-05 16:10:02 Functions: 100.0 % 25 25
Legend: Lines:     hit not hit

            Line data    Source code
       1              : // Copyright (C) 2024-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 "rust-collect-lang-items.h"
      20              : #include "optional.h"
      21              : #include "rust-ast-collector.h"
      22              : #include "rust-ast-visitor.h"
      23              : #include "rust-ast.h"
      24              : #include "rust-attribute-values.h"
      25              : #include "rust-attributes.h"
      26              : #include "rust-hir-map.h"
      27              : #include "rust-item.h"
      28              : 
      29              : namespace Rust {
      30              : namespace AST {
      31              : 
      32              : template <typename T>
      33              : tl::optional<LangItem::Kind>
      34       191002 : get_lang_item_attr (const T &maybe_lang_item)
      35              : {
      36       923661 :   for (const auto &attr : maybe_lang_item.get_outer_attrs ())
      37              :     {
      38       732659 :       const auto &str_path = attr.get_path ().as_string ();
      39              : 
      40              :       // Attribute checking is done elsewhere, we can just check whether or not
      41              :       // we're dealing with a lang item here
      42              : 
      43       732659 :       bool is_lang_item = str_path == Values::Attributes::LANG;
      44              : 
      45       732659 :       if (is_lang_item)
      46              :         {
      47         5197 :           auto lang_item_type_str
      48              :             = Analysis::Attributes::extract_string_literal (attr);
      49              : 
      50         5197 :           rust_assert (lang_item_type_str.has_value ());
      51              : 
      52         5197 :           return LangItem::Parse (*lang_item_type_str);
      53         5197 :         }
      54              :     }
      55              : 
      56       185805 :   return tl::nullopt;
      57              : }
      58              : 
      59              : template <typename T>
      60              : void
      61       191002 : CollectLangItems::maybe_add_lang_item (const T &item)
      62              : {
      63       191002 :   if (auto lang_item = get_lang_item_attr (item))
      64         5185 :     mappings.insert_lang_item_node (lang_item.value (), item.get_node_id ());
      65       191002 : }
      66              : 
      67              : void
      68         6319 : CollectLangItems::visit (AST::Trait &item)
      69              : {
      70         6319 :   maybe_add_lang_item (item);
      71              : 
      72         6319 :   DefaultASTVisitor::visit (item);
      73         6319 : }
      74              : 
      75              : void
      76         1326 : CollectLangItems::visit (AST::TraitItemType &item)
      77              : {
      78         1326 :   maybe_add_lang_item (item);
      79              : 
      80         1326 :   DefaultASTVisitor::visit (item);
      81         1326 : }
      82              : 
      83              : void
      84       171688 : CollectLangItems::visit (AST::Function &item)
      85              : {
      86       171688 :   maybe_add_lang_item (item);
      87              : 
      88       171688 :   DefaultASTVisitor::visit (item);
      89       171688 : }
      90              : 
      91              : void
      92         9105 : CollectLangItems::visit (AST::StructStruct &item)
      93              : {
      94         9105 :   maybe_add_lang_item (item);
      95              : 
      96         9105 :   DefaultASTVisitor::visit (item);
      97         9105 : }
      98              : 
      99              : void
     100         1254 : CollectLangItems::visit (AST::EnumItem &item)
     101              : {
     102         1254 :   maybe_add_lang_item (item);
     103              : 
     104         1254 :   DefaultASTVisitor::visit (item);
     105         1254 : }
     106              : 
     107              : void
     108          875 : CollectLangItems::visit (AST::EnumItemTuple &item)
     109              : {
     110          875 :   maybe_add_lang_item (item);
     111              : 
     112          875 :   DefaultASTVisitor::visit (item);
     113          875 : }
     114              : 
     115              : void
     116          103 : CollectLangItems::visit (AST::EnumItemStruct &item)
     117              : {
     118          103 :   maybe_add_lang_item (item);
     119              : 
     120          103 :   DefaultASTVisitor::visit (item);
     121          103 : }
     122              : 
     123              : void
     124          332 : CollectLangItems::visit (AST::EnumItemDiscriminant &item)
     125              : {
     126          332 :   maybe_add_lang_item (item);
     127              : 
     128          332 :   DefaultASTVisitor::visit (item);
     129          332 : }
     130              : 
     131              : void
     132           89 : CollectLangItems::visit (AST::ExternCrate &extern_crate)
     133              : {
     134           89 :   auto &crate_mappings = Analysis::Mappings::get ().crate;
     135           89 :   auto crate_num
     136           89 :     = crate_mappings.lookup_crate_name (extern_crate.get_referenced_crate ());
     137           89 :   if (crate_num)
     138              :     {
     139           85 :       visit (crate_mappings.get_ast_crate (*crate_num));
     140              :     }
     141              : 
     142           89 :   DefaultASTVisitor::visit (extern_crate);
     143           89 : }
     144              : 
     145              : } // namespace AST
     146              : } // 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.