LCOV - code coverage report
Current view: top level - gcc/rust/util - rust-lang-item.h Coverage Total Hit
Test: gcc.info Lines: 100.0 % 2 2
Test Date: 2026-02-28 14:20:25 Functions: - 0 0
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 "rust-system.h"
      20              : #include "rust-operators.h"
      21              : #include "optional.h"
      22              : #include "bi-map.h"
      23              : 
      24              : #ifndef RUST_LANG_ITEM_H
      25              : #define RUST_LANG_ITEM_H
      26              : 
      27              : namespace Rust {
      28              : 
      29              : class LangItem
      30              : {
      31              : public:
      32              :   // FIXME: We should clean up that enum to make it more inline with the list of
      33              :   // lang-items in Rust 1.49
      34              :   // https://github.com/rust-lang/rust/blob/1.49.0/compiler/rustc_hir/src/lang_items.rs
      35              :   enum class Kind
      36              :   {
      37              :     // https://github.com/rust-lang/rust/blob/master/library/core/src/ops/arith.rs
      38              :     ADD,
      39              :     SUBTRACT,
      40              :     MULTIPLY,
      41              :     DIVIDE,
      42              :     REMAINDER,
      43              :     BITAND,
      44              :     BITOR,
      45              :     BITXOR,
      46              :     SHL,
      47              :     SHR,
      48              : 
      49              :     NEGATION,
      50              :     NOT,
      51              :     EQ,
      52              :     PARTIAL_ORD,
      53              : 
      54              :     ADD_ASSIGN,
      55              :     SUB_ASSIGN,
      56              :     MUL_ASSIGN,
      57              :     DIV_ASSIGN,
      58              :     REM_ASSIGN,
      59              :     BITAND_ASSIGN,
      60              :     BITOR_ASSIGN,
      61              :     BITXOR_ASSIGN,
      62              :     SHL_ASSIGN,
      63              :     SHR_ASSIGN,
      64              : 
      65              :     DEREF,
      66              :     DEREF_MUT,
      67              :     RECEIVER,
      68              : 
      69              :     // https://github.com/rust-lang/rust/blob/master/library/core/src/ops/index.rs
      70              :     INDEX,
      71              :     INDEX_MUT,
      72              : 
      73              :     // https://github.com/rust-lang/rust/blob/master/library/core/src/ops/range.rs
      74              :     RANGE_FULL,
      75              :     RANGE,
      76              :     RANGE_FROM,
      77              :     RANGE_TO,
      78              :     RANGE_INCLUSIVE,
      79              :     RANGE_TO_INCLUSIVE,
      80              : 
      81              :     // https://github.com/rust-lang/rust/blob/master/library/core/src/marker.rs
      82              :     PHANTOM_DATA,
      83              : 
      84              :     // functions
      85              :     FN,
      86              :     FN_MUT,
      87              :     FN_ONCE,
      88              :     FN_ONCE_OUTPUT,
      89              : 
      90              :     // markers
      91              :     COPY,
      92              :     CLONE,
      93              :     SIZED,
      94              :     SYNC,
      95              : 
      96              :     // https://github.com/Rust-GCC/gccrs/issues/1896
      97              :     // https://github.com/rust-lang/rust/commit/afbecc0f68c4dcfc4878ba5bcb1ac942544a1bdc
      98              :     // https://github.com/Rust-GCC/gccrs/issues/1494
      99              :     // https://github.com/rust-lang/rust/blob/master/library/core/src/ptr/const_ptr.rs
     100              :     SLICE_ALLOC,
     101              :     SLICE_U8_ALLOC,
     102              :     STR_ALLOC,
     103              :     ARRAY,
     104              :     BOOL,
     105              :     CHAR,
     106              :     F32,
     107              :     F64,
     108              :     I8,
     109              :     I16,
     110              :     I32,
     111              :     I64,
     112              :     I128,
     113              :     ISIZE,
     114              :     U8,
     115              :     U16,
     116              :     U32,
     117              :     U64,
     118              :     U128,
     119              :     USIZE,
     120              :     CONST_PTR,
     121              :     CONST_SLICE_PTR,
     122              :     MUT_PTR,
     123              :     MUT_SLICE_PTR,
     124              :     SLICE_U8,
     125              :     SLICE,
     126              :     STR,
     127              :     F32_RUNTIME,
     128              :     F64_RUNTIME,
     129              : 
     130              :     OPTION_SOME,
     131              :     OPTION_NONE,
     132              : 
     133              :     RESULT_OK,
     134              :     RESULT_ERR,
     135              : 
     136              :     INTOITER_INTOITER,
     137              :     ITERATOR_NEXT,
     138              : 
     139              :     // NOTE: These lang items are *not* necessarily present in later versions of
     140              :     // Rust (I am unsure at which point they have been removed as the `Try`
     141              :     // trait is unstable). They will need to be changed when updating the
     142              :     // targeted Rust version of gccrs
     143              :     TRY,
     144              :     TRY_INTO_RESULT,
     145              :     TRY_FROM_ERROR,
     146              :     TRY_FROM_OK,
     147              : 
     148              :     // NOTE: This is not a lang item in later versions of Rust
     149              :     FROM_FROM,
     150              : 
     151              :     STRUCTURAL_PEQ,
     152              :     STRUCTURAL_TEQ,
     153              : 
     154              :     DISCRIMINANT_TYPE,
     155              :     DISCRIMINANT_KIND,
     156              : 
     157              :     MANUALLY_DROP,
     158              :   };
     159              : 
     160              :   static const BiMap<std::string, Kind> lang_items;
     161              : 
     162              :   static tl::optional<Kind> Parse (const std::string &item);
     163              : 
     164              :   static std::string ToString (Kind type);
     165              :   static std::string PrettyString (Kind type);
     166              : 
     167              :   static Kind OperatorToLangItem (ArithmeticOrLogicalOperator op);
     168              :   static Kind
     169              :   CompoundAssignmentOperatorToLangItem (ArithmeticOrLogicalOperator op);
     170              :   static Kind NegationOperatorToLangItem (NegationOperator op);
     171              :   static Kind ComparisonToLangItem (ComparisonOperator op);
     172              :   static std::string ComparisonToSegment (ComparisonOperator op);
     173              : 
     174              :   static bool IsEnumVariant (Kind type);
     175              : };
     176              : 
     177              : } // namespace Rust
     178              : 
     179              : // GCC 4.8 needs us to manually implement hashing for enum classes
     180              : namespace std {
     181              : template <> struct hash<Rust::LangItem::Kind>
     182              : {
     183      1382576 :   size_t operator() (const Rust::LangItem::Kind &lang_item) const noexcept
     184              :   {
     185      1382576 :     return hash<std::underlying_type<Rust::LangItem::Kind>::type> () (
     186              :       static_cast<std::underlying_type<Rust::LangItem::Kind>::type> (
     187              :         lang_item));
     188              :   }
     189              : };
     190              : } // namespace std
     191              : 
     192              : #endif // RUST_LANG_ITEM_H
        

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.