Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | Static Private Attributes | List of all members
ConditionStack Class Reference

A data type to abstract out the condition stack during script execution. More...

#include <conditionstack.h>

Public Member Functions

bool empty () const
 
bool all_true () const
 
void push_back (bool f)
 
void pop_back ()
 
void toggle_top ()
 

Private Attributes

uint32_t m_stack_size = 0
 The size of the implied stack.
 
uint32_t m_first_false_pos = NO_FALSE
 The position of the first false value on the implied stack, or NO_FALSE if all true.
 

Static Private Attributes

static constexpr uint32_t NO_FALSE = std::numeric_limits<uint32_t>::max()
 A constant for m_first_false_pos to indicate there are no falses.
 

Detailed Description

A data type to abstract out the condition stack during script execution.

Conceptually it acts like a vector of booleans, one for each level of nested IF/THEN/ELSE, indicating whether we're in the active or inactive branch of each.

The elements on the stack cannot be observed individually; we only need to expose whether the stack is empty and whether or not any false values are present at all. To implement OP_ELSE, a toggle_top modifier is added, which flips the last value without returning it.

This uses an optimized implementation that does not materialize the actual stack. Instead, it just stores the size of the would-be stack, and the position of the first false value in it.

Definition at line 28 of file conditionstack.h.

Member Function Documentation

◆ all_true()

bool ConditionStack::all_true ( ) const
inline

Definition at line 41 of file conditionstack.h.

Here is the caller graph for this function:

◆ empty()

bool ConditionStack::empty ( ) const
inline

Definition at line 40 of file conditionstack.h.

Here is the caller graph for this function:

◆ pop_back()

void ConditionStack::pop_back ( )
inline

Definition at line 50 of file conditionstack.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_back()

void ConditionStack::push_back ( bool  f)
inline

Definition at line 42 of file conditionstack.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toggle_top()

void ConditionStack::toggle_top ( )
inline

Definition at line 58 of file conditionstack.h.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_first_false_pos

uint32_t ConditionStack::m_first_false_pos = NO_FALSE
private

The position of the first false value on the implied stack, or NO_FALSE if all true.

Definition at line 37 of file conditionstack.h.

◆ m_stack_size

uint32_t ConditionStack::m_stack_size = 0
private

The size of the implied stack.

Definition at line 34 of file conditionstack.h.

◆ NO_FALSE

constexpr uint32_t ConditionStack::NO_FALSE = std::numeric_limits<uint32_t>::max()
staticconstexprprivate

A constant for m_first_false_pos to indicate there are no falses.

Definition at line 31 of file conditionstack.h.


The documentation for this class was generated from the following file: