LCOV - code coverage report
Current view: top level - src/script - verify_flags.h (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 100.0 % 11 11
Test Date: 2025-10-10 04:04:55 Functions: 100.0 % 1 1
Branches: 80.0 % 100 80

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2                 :             : // Copyright (c) 2009-present The Bitcoin Core developers
       3                 :             : // Distributed under the MIT software license, see the accompanying
       4                 :             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       5                 :             : 
       6                 :             : #ifndef BITCOIN_SCRIPT_VERIFY_FLAGS_H
       7                 :             : #define BITCOIN_SCRIPT_VERIFY_FLAGS_H
       8                 :             : 
       9                 :             : #include <compare>
      10                 :             : #include <cstdint>
      11                 :             : 
      12                 :             : enum class script_verify_flag_name : uint8_t;
      13                 :             : 
      14                 :             : class script_verify_flags
      15                 :             : {
      16                 :             : public:
      17                 :             :     using value_type = uint64_t;
      18                 :             : 
      19                 :             :     consteval script_verify_flags() = default;
      20                 :             : 
      21                 :             :     // also allow construction with hard-coded 0 (but not other integers)
      22                 :             :     consteval explicit(false) script_verify_flags(value_type f) : m_value{f} { if (f != 0) throw 0; }
      23                 :             : 
      24                 :             :     // implicit construction from a hard-coded SCRIPT_VERIFY_* constant is also okay
      25                 :          75 :     constexpr explicit(false) script_verify_flags(script_verify_flag_name f) : m_value{value_type{1} << static_cast<uint8_t>(f)} { }
      26                 :             : 
      27                 :             :     // rule of 5
      28                 :             :     constexpr script_verify_flags(const script_verify_flags&) = default;
      29                 :             :     constexpr script_verify_flags(script_verify_flags&&) = default;
      30                 :             :     constexpr script_verify_flags& operator=(const script_verify_flags&) = default;
      31                 :             :     constexpr script_verify_flags& operator=(script_verify_flags&&) = default;
      32                 :             :     constexpr ~script_verify_flags() = default;
      33                 :             : 
      34                 :             :     // integer conversion needs to be very explicit
      35         [ +  + ]:     9548933 :     static constexpr script_verify_flags from_int(value_type f) { script_verify_flags r; r.m_value = f; return r; }
      36                 :        2039 :     constexpr value_type as_int() const { return m_value; }
      37                 :             : 
      38                 :             :     // bitwise operations
      39                 :       23604 :     constexpr script_verify_flags operator~() const { return from_int(~m_value); }
      40                 :         328 :     friend constexpr script_verify_flags operator|(script_verify_flags a, script_verify_flags b) { return from_int(a.m_value | b.m_value); }
      41   [ +  +  +  +  :     2661041 :     friend constexpr script_verify_flags operator&(script_verify_flags a, script_verify_flags b) { return from_int(a.m_value & b.m_value); }
          +  +  +  -  +  
          +  -  +  -  -  
          +  -  -  -  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
             +  +  +  + ]
         [ +  + ][ -  -  
          +  +  +  +  +  
           +  +  + ][ +  
          +  +  +  +  +  
                   +  + ]
      42                 :             : 
      43                 :             :     // in-place bitwise operations
      44                 :     1162517 :     constexpr script_verify_flags& operator|=(script_verify_flags vf) { m_value |= vf.m_value; return *this; }
      45                 :        4994 :     constexpr script_verify_flags& operator&=(script_verify_flags vf) { m_value &= vf.m_value; return *this; }
      46                 :             : 
      47                 :             :     // tests
      48                 :             :     constexpr explicit operator bool() const { return m_value != 0; }
      49   [ +  -  +  +  :     5150199 :     constexpr bool operator==(script_verify_flags other) const { return m_value == other.m_value; }
          -  +  +  +  -  
          +  +  +  +  +  
          -  +  -  +  -  
          +  -  -  +  +  
          +  +  +  +  +  
                +  +  + ]
           [ +  -  #  # ]
           [ +  +  +  + ]
      50                 :             : 
      51                 :             :     /** Compare two script_verify_flags. <, >, <=, and >= are auto-generated from this. */
      52                 :             :     friend constexpr std::strong_ordering operator<=>(const script_verify_flags& a, const script_verify_flags& b) noexcept
      53                 :             :     {
      54                 :             :         return a.m_value <=> b.m_value;
      55                 :             :     }
      56                 :             : 
      57                 :             : private:
      58                 :             :     value_type m_value{0}; // default value is SCRIPT_VERIFY_NONE
      59                 :             : };
      60                 :             : 
      61                 :          12 : inline constexpr script_verify_flags operator~(script_verify_flag_name f)
      62                 :             : {
      63                 :          12 :     return ~script_verify_flags{f};
      64                 :             : }
      65                 :             : 
      66                 :             : inline constexpr script_verify_flags operator|(script_verify_flag_name f1, script_verify_flag_name f2)
      67                 :             : {
      68                 :             :     return script_verify_flags{f1} | f2;
      69                 :             : }
      70                 :             : 
      71                 :             : #endif // BITCOIN_SCRIPT_VERIFY_FLAGS_H
        

Generated by: LCOV version 2.0-1