KiCad PCB EDA Suite
PCB_EXPR_UCODE Class Referencefinal

#include <pcb_expr_evaluator.h>

Inheritance diagram for PCB_EXPR_UCODE:
LIBEVAL::UCODE

Public Member Functions

 PCB_EXPR_UCODE ()
 
virtual ~PCB_EXPR_UCODE ()
 
virtual std::unique_ptr< LIBEVAL::VAR_REFCreateVarRef (const wxString &aVar, const wxString &aField) override
 
virtual LIBEVAL::FUNC_CALL_REF CreateFuncCall (const wxString &aName) override
 
void AddOp (UOP *uop)
 
VALUERun (CONTEXT *ctx)
 
wxString Dump () const
 

Protected Attributes

std::vector< UOP * > m_ucode
 

Detailed Description

Definition at line 40 of file pcb_expr_evaluator.h.

Constructor & Destructor Documentation

◆ PCB_EXPR_UCODE()

PCB_EXPR_UCODE::PCB_EXPR_UCODE ( )
inline

Definition at line 43 of file pcb_expr_evaluator.h.

43 {};

◆ ~PCB_EXPR_UCODE()

virtual PCB_EXPR_UCODE::~PCB_EXPR_UCODE ( )
inlinevirtual

Definition at line 44 of file pcb_expr_evaluator.h.

44 {};

Member Function Documentation

◆ AddOp()

void LIBEVAL::UCODE::AddOp ( UOP uop)
inlineinherited

Definition at line 324 of file libeval_compiler.h.

325  {
326  m_ucode.push_back(uop);
327  }
std::vector< UOP * > m_ucode

References LIBEVAL::UCODE::m_ucode.

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

◆ CreateFuncCall()

LIBEVAL::FUNC_CALL_REF PCB_EXPR_UCODE::CreateFuncCall ( const wxString &  aName)
overridevirtual

Reimplemented from LIBEVAL::UCODE.

Definition at line 573 of file pcb_expr_evaluator.cpp.

574 {
576 
577  return registry.Get( aName.Lower() );
578 }
LIBEVAL::FUNC_CALL_REF Get(const wxString &name)
static PCB_EXPR_BUILTIN_FUNCTIONS & Instance()

References PCB_EXPR_BUILTIN_FUNCTIONS::Get(), and PCB_EXPR_BUILTIN_FUNCTIONS::Instance().

◆ CreateVarRef()

std::unique_ptr< LIBEVAL::VAR_REF > PCB_EXPR_UCODE::CreateVarRef ( const wxString &  aVar,
const wxString &  aField 
)
overridevirtual

Reimplemented from LIBEVAL::UCODE.

Definition at line 581 of file pcb_expr_evaluator.cpp.

583 {
585  std::unique_ptr<PCB_EXPR_VAR_REF> vref;
586 
587  if( aVar == "A" )
588  vref = std::make_unique<PCB_EXPR_VAR_REF>( 0 );
589  else if( aVar == "B" )
590  vref = std::make_unique<PCB_EXPR_VAR_REF>( 1 );
591  else if( aVar == "L" )
592  vref = std::make_unique<PCB_EXPR_VAR_REF>( 2 );
593  else
594  return nullptr;
595 
596  if( aField.length() == 0 ) // return reference to base object
597  {
598  return std::move( vref );
599  }
600 
601  wxString field( aField );
602  field.Replace( "_", " " );
603 
604  for( const PROPERTY_MANAGER::CLASS_INFO& cls : propMgr.GetAllClasses() )
605  {
606  if( propMgr.IsOfType( cls.type, TYPE_HASH( BOARD_ITEM ) ) )
607  {
608  PROPERTY_BASE* prop = propMgr.GetProperty( cls.type, field );
609 
610  if( prop )
611  {
612  vref->AddAllowedClass( cls.type, prop );
613 
614  if( prop->TypeHash() == TYPE_HASH( int ) )
615  {
616  vref->SetType( LIBEVAL::VT_NUMERIC );
617  }
618  else if( prop->TypeHash() == TYPE_HASH( wxString ) )
619  {
620  vref->SetType( LIBEVAL::VT_STRING );
621  }
622  else if ( prop->HasChoices() )
623  { // it's an enum, we treat it as string
624  vref->SetType( LIBEVAL::VT_STRING );
625  vref->SetIsEnum ( true );
626  }
627  else
628  {
629  wxFAIL_MSG( "PCB_EXPR_UCODE::createVarRef: Unknown property type." );
630  }
631  }
632  }
633  }
634 
635  if( vref->GetType() == LIBEVAL::VT_UNDEFINED )
636  vref->SetType( LIBEVAL::VT_PARSE_ERROR );
637 
638  return std::move( vref );
639 }
virtual bool HasChoices() const
Returns true if this PROPERTY has a limited set of possible values.
Definition: property.h:215
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:64
#define TYPE_HASH(x)
Macro to generate unique identifier for a type
Definition: property.h:55
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
virtual size_t TypeHash() const =0
Returns type-id of the property type.
PROPERTY_BASE * GetProperty(TYPE_ID aType, const wxString &aProperty) const
Returns a property for a specific type.
bool IsOfType(TYPE_ID aDerived, TYPE_ID aBase) const
Returns true if aDerived is inherited from aBase.
CLASSES_INFO GetAllClasses()
Provides class metadata.
Definition: property_mgr.h:61

References PROPERTY_MANAGER::GetAllClasses(), PROPERTY_MANAGER::GetProperty(), PROPERTY_BASE::HasChoices(), PROPERTY_MANAGER::Instance(), PROPERTY_MANAGER::IsOfType(), TYPE_HASH, PROPERTY_BASE::TypeHash(), LIBEVAL::VT_NUMERIC, LIBEVAL::VT_PARSE_ERROR, LIBEVAL::VT_STRING, and LIBEVAL::VT_UNDEFINED.

◆ Dump()

wxString LIBEVAL::UCODE::Dump ( ) const
inherited

Definition at line 175 of file libeval_compiler.cpp.

176 {
177  wxString rv;
178 
179  for( auto op : m_ucode )
180  {
181  rv += op->Format();
182  rv += "\n";
183  }
184 
185  return rv;
186 };
std::vector< UOP * > m_ucode

References LIBEVAL::UCODE::m_ucode.

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

◆ Run()

VALUE * LIBEVAL::UCODE::Run ( CONTEXT ctx)
inherited

Definition at line 1165 of file libeval_compiler.cpp.

1166 {
1167  static VALUE g_false( 0 );
1168 
1169  try
1170  {
1171  for( UOP* op : m_ucode )
1172  op->Exec( ctx );
1173  }
1174  catch(...)
1175  {
1176  // rules which fail outright should not be fired
1177  return &g_false;
1178  }
1179 
1180  if( ctx->SP() == 1 )
1181  {
1182  return ctx->Pop();
1183  }
1184  else
1185  {
1186  // If stack is corrupted after execution it suggests a problem with the compiler, not
1187  // the rule....
1188 
1189  // do not use "assert"; it crashes outright on OSX
1190  wxASSERT( ctx->SP() == 1 );
1191 
1192  // non-well-formed rules should not be fired on a release build
1193  return &g_false;
1194  }
1195 }
Field Value of part, i.e. "3.3K".
std::vector< UOP * > m_ucode

References LIBEVAL::UCODE::m_ucode, LIBEVAL::CONTEXT::Pop(), and LIBEVAL::CONTEXT::SP().

Referenced by PCB_EXPR_EVALUATOR::Evaluate(), and testEvalExpr().

Member Data Documentation

◆ m_ucode

std::vector<UOP*> LIBEVAL::UCODE::m_ucode
protectedinherited

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