LCOV - code coverage report
Current view: top level - gcc/rust/util - rust-mapping-common.h Coverage Total Hit
Test: gcc.info Lines: 100.0 % 10 10
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              : #ifndef RUST_MAPPING_COMMON
      20              : #define RUST_MAPPING_COMMON
      21              : 
      22              : #include "rust-system.h"
      23              : 
      24              : namespace Rust {
      25              : 
      26              : // refers to a Crate
      27              : typedef uint32_t CrateNum;
      28              : // refers to any node in the AST in current Crate
      29              : typedef uint32_t NodeId;
      30              : // refers to any node in the HIR for the current crate
      31              : typedef uint32_t HirId;
      32              : // refers to any top-level decl in HIR
      33              : typedef uint32_t LocalDefId;
      34              : 
      35              : struct DefId
      36              : {
      37              :   CrateNum crateNum;
      38              :   LocalDefId localDefId;
      39              : 
      40       529296 :   bool operator== (const DefId &other) const
      41              :   {
      42       529296 :     return this->crateNum == other.crateNum
      43       529288 :            && this->localDefId == other.localDefId;
      44              :   }
      45              : 
      46        94130 :   bool operator!= (const DefId &other) const { return !(*this == other); }
      47              : 
      48      5249452 :   bool operator< (const DefId &other) const
      49              :   {
      50        11016 :     return ((uint64_t) this->crateNum << 32 | this->localDefId)
      51      5241007 :            < ((uint64_t) other.crateNum << 32 | other.localDefId);
      52              :   }
      53              : 
      54              :   std::string as_string () const
      55              :   {
      56              :     std::string buf;
      57              :     buf += std::to_string (crateNum);
      58              :     buf += " "; // or anything else
      59              :     buf += std::to_string (localDefId);
      60              :     return buf;
      61              :   }
      62              : };
      63              : 
      64              : #define UNKNOWN_CRATENUM ((uint32_t) (UINT32_MAX))
      65              : #define UNKNOWN_NODEID ((uint32_t) (UINT32_MAX))
      66              : #define MAX_NODEID (UNKNOWN_NODEID - 1)
      67              : #define UNKNOWN_HIRID ((uint32_t) (UINT32_MAX))
      68              : #define UNKNOWN_LOCAL_DEFID ((uint32_t) (0))
      69              : #define UNKNOWN_DEFID (DefId{0, 0})
      70              : 
      71              : } // namespace Rust
      72              : 
      73              : namespace std {
      74              : template <> struct hash<Rust::DefId>
      75              : {
      76        75026 :   size_t operator() (const Rust::DefId &id) const noexcept
      77              :   {
      78              :     // TODO: Check if we can improve performance by having a better hash
      79              :     // algorithm for `DefId`s
      80        75026 :     return hash<uint32_t> () (hash<uint32_t> () (id.crateNum)
      81        75026 :                               + hash<uint32_t> () (id.localDefId));
      82              :   }
      83              : };
      84              : } // namespace std
      85              : 
      86              : #endif // RUST_MAPPING_COMMON
        

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.