KiCad PCB EDA Suite
Loading...
Searching...
No Matches
LIBEVAL::CONTEXT Class Reference

#include <libeval_compiler.h>

Inheritance diagram for LIBEVAL::CONTEXT:
PCBEXPR_CONTEXT

Classes

struct  STACK_OVERFLOW
 

Public Types

using ERROR_CALLBACK = std::function<void( const wxString& aMessage, int aOffset )>
 

Public Member Functions

 CONTEXT ()
 
virtual ~CONTEXT ()
 
 CONTEXT (const CONTEXT &)=delete
 
CONTEXT & operator= (const CONTEXT &)=delete
 
virtual void Reset ()
 Release every value allocated by the previous evaluation and rewind the stack so the same CONTEXT can be reused for another Run() without being reconstructed.
 
VALUE * AllocValue ()
 
VALUE * StoreValue (VALUE *aValue)
 
void Push (VALUE *aValue)
 
VALUE * Pop ()
 
VALUE * Top ()
 Peek the top of the stack without popping (used by the short-circuit jumps).
 
int SP () const
 
void ClearStack ()
 Discard operands while retaining allocated values and context settings.
 
void SetErrorCallback (ERROR_CALLBACK aCallback)
 
ERROR_CALLBACK ExchangeErrorCallback (ERROR_CALLBACK aCallback)
 Install a callback and return the previous one.
 
bool HasErrorCallback ()
 
void ReportError (const wxString &aErrorMsg)
 

Static Public Attributes

static constexpr int STACK_CAPACITY = 100
 

Private Member Functions

void stackOverflow ()
 
VALUE * inlineValue (std::size_t aIndex)
 

Private Attributes

std::vector< VALUE * > m_ownedValues
 
VALUE * m_stack [STACK_CAPACITY]
 
int m_stackPtr
 
unsigned char m_inlineStorage [INLINE_VALUE_COUNT *sizeof(VALUE)]
 
std::size_t m_inlineUsed
 
ERROR_CALLBACK m_errorCallback
 

Static Private Attributes

static constexpr std::size_t INLINE_VALUE_COUNT = 32
 

Detailed Description

Definition at line 352 of file libeval_compiler.h.

Member Typedef Documentation

◆ ERROR_CALLBACK

using LIBEVAL::CONTEXT::ERROR_CALLBACK = std::function<void( const wxString& aMessage, int aOffset )>

Definition at line 357 of file libeval_compiler.h.

Constructor & Destructor Documentation

◆ CONTEXT() [1/2]

LIBEVAL::CONTEXT::CONTEXT ( )
inline

Definition at line 361 of file libeval_compiler.h.

References m_inlineUsed, m_ownedValues, m_stack, and m_stackPtr.

Referenced by CONTEXT(), and operator=().

◆ ~CONTEXT()

virtual LIBEVAL::CONTEXT::~CONTEXT ( )
inlinevirtual

Definition at line 369 of file libeval_compiler.h.

References Reset().

◆ CONTEXT() [2/2]

LIBEVAL::CONTEXT::CONTEXT ( const CONTEXT & )
delete

References CONTEXT().

Member Function Documentation

◆ AllocValue()

◆ ClearStack()

void LIBEVAL::CONTEXT::ClearStack ( )
inline

Discard operands while retaining allocated values and context settings.

Definition at line 460 of file libeval_compiler.h.

References m_stackPtr.

Referenced by LIBEVAL::COMPILER::generateUCode(), and LIBEVAL::UCODE::Run().

◆ ExchangeErrorCallback()

ERROR_CALLBACK LIBEVAL::CONTEXT::ExchangeErrorCallback ( ERROR_CALLBACK aCallback)
inline

Install a callback and return the previous one.

Definition at line 471 of file libeval_compiler.h.

References m_errorCallback.

Referenced by LIBEVAL::COMPILER::generateUCode().

◆ HasErrorCallback()

◆ inlineValue()

VALUE * LIBEVAL::CONTEXT::inlineValue ( std::size_t aIndex)
inlineprivate

Definition at line 486 of file libeval_compiler.h.

References m_inlineStorage.

Referenced by AllocValue(), and Reset().

◆ operator=()

CONTEXT & LIBEVAL::CONTEXT::operator= ( const CONTEXT & )
delete

References CONTEXT().

◆ Pop()

◆ Push()

◆ ReportError()

◆ Reset()

virtual void LIBEVAL::CONTEXT::Reset ( )
inlinevirtual

Release every value allocated by the previous evaluation and rewind the stack so the same CONTEXT can be reused for another Run() without being reconstructed.

This keeps the owned- value vector's buffer allocated, so a reused context performs zero heap allocation for the common evaluation. Overrides must chain to this base after rewinding their own per-run state.

Reimplemented in PCBEXPR_CONTEXT.

Definition at line 385 of file libeval_compiler.h.

References inlineValue(), m_errorCallback, m_inlineUsed, m_ownedValues, and m_stackPtr.

Referenced by PCBEXPR_CONTEXT::Reset(), and ~CONTEXT().

◆ SetErrorCallback()

◆ SP()

int LIBEVAL::CONTEXT::SP ( ) const
inline

Definition at line 454 of file libeval_compiler.h.

References m_stackPtr.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and LIBEVAL::UCODE::Run().

◆ stackOverflow()

void LIBEVAL::CONTEXT::stackOverflow ( )
private

Definition at line 718 of file libeval_compiler.cpp.

References _, and ReportError().

Referenced by Push().

◆ StoreValue()

VALUE * LIBEVAL::CONTEXT::StoreValue ( VALUE * aValue)
inline

Definition at line 417 of file libeval_compiler.h.

References m_ownedValues.

Referenced by LIBEVAL::UOP::Exec(), and LIBEVAL::UCODE::Run().

◆ Top()

VALUE * LIBEVAL::CONTEXT::Top ( )
inline

Peek the top of the stack without popping (used by the short-circuit jumps).

Definition at line 443 of file libeval_compiler.h.

References _, AllocValue(), m_stack, m_stackPtr, and ReportError().

Referenced by LIBEVAL::UOP::Exec().

Member Data Documentation

◆ INLINE_VALUE_COUNT

std::size_t LIBEVAL::CONTEXT::INLINE_VALUE_COUNT = 32
staticconstexprprivate

Definition at line 482 of file libeval_compiler.h.

Referenced by AllocValue().

◆ m_errorCallback

ERROR_CALLBACK LIBEVAL::CONTEXT::m_errorCallback
private

◆ m_inlineStorage

unsigned char LIBEVAL::CONTEXT::m_inlineStorage[INLINE_VALUE_COUNT *sizeof(VALUE)]
private

Definition at line 495 of file libeval_compiler.h.

Referenced by inlineValue().

◆ m_inlineUsed

std::size_t LIBEVAL::CONTEXT::m_inlineUsed
private

Definition at line 496 of file libeval_compiler.h.

Referenced by AllocValue(), CONTEXT(), and Reset().

◆ m_ownedValues

std::vector<VALUE*> LIBEVAL::CONTEXT::m_ownedValues
private

Definition at line 491 of file libeval_compiler.h.

Referenced by AllocValue(), CONTEXT(), Reset(), and StoreValue().

◆ m_stack

VALUE* LIBEVAL::CONTEXT::m_stack[STACK_CAPACITY]
private

Definition at line 492 of file libeval_compiler.h.

Referenced by CONTEXT(), Pop(), Push(), and Top().

◆ m_stackPtr

int LIBEVAL::CONTEXT::m_stackPtr
private

Definition at line 493 of file libeval_compiler.h.

Referenced by ClearStack(), CONTEXT(), Pop(), Push(), Reset(), SP(), and Top().

◆ STACK_CAPACITY

int LIBEVAL::CONTEXT::STACK_CAPACITY = 100
staticconstexpr

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