Coverage Report

Created: 2026-04-29 19:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/tmp/bitcoin/src/script/verify_flags.h
Line
Count
Source
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
0
    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
12.0M
    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
12.3M
    static constexpr script_verify_flags from_int(value_type f) { script_verify_flags r; r.m_value = f; return r; }
36
298k
    constexpr value_type as_int() const { return m_value; }
37
38
    // bitwise operations
39
395k
    constexpr script_verify_flags operator~() const { return from_int(~m_value); }
40
1.09M
    friend constexpr script_verify_flags operator|(script_verify_flags a, script_verify_flags b) { return from_int(a.m_value | b.m_value); }
41
10.4M
    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
835k
    constexpr script_verify_flags& operator|=(script_verify_flags vf) { m_value |= vf.m_value; return *this; }
45
12.2k
    constexpr script_verify_flags& operator&=(script_verify_flags vf) { m_value &= vf.m_value; return *this; }
46
47
    // tests
48
4.56M
    constexpr explicit operator bool() const { return m_value != 0; }
49
5.70M
    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
1.06k
    {
54
1.06k
        return a.m_value <=> b.m_value;
55
1.06k
    }
56
57
private:
58
    value_type m_value{0}; // default value is SCRIPT_VERIFY_NONE
59
};
60
61
inline constexpr script_verify_flags operator~(script_verify_flag_name f)
62
16.5k
{
63
16.5k
    return ~script_verify_flags{f};
64
16.5k
}
65
66
inline constexpr script_verify_flags operator|(script_verify_flag_name f1, script_verify_flag_name f2)
67
528k
{
68
528k
    return script_verify_flags{f1} | f2;
69
528k
}
70
71
#endif // BITCOIN_SCRIPT_VERIFY_FLAGS_H