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)
 
VALUE * Run (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 371 of file libeval_compiler.h.

372 {
373 m_ucode.push_back(uop);
374 }
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 1075 of file pcb_expr_evaluator.cpp.

1076{
1078
1079 return registry.Get( aName.Lower() );
1080}
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 1083 of file pcb_expr_evaluator.cpp.

1085{
1087 std::unique_ptr<PCB_EXPR_VAR_REF> vref;
1088
1089 // Check for a couple of very common cases and compile them straight to "object code".
1090
1091 if( aField.CmpNoCase( wxT( "NetClass" ) ) == 0 )
1092 {
1093 if( aVar == wxT( "A" ) )
1094 return std::make_unique<PCB_EXPR_NETCLASS_REF>( 0 );
1095 else if( aVar == wxT( "B" ) )
1096 return std::make_unique<PCB_EXPR_NETCLASS_REF>( 1 );
1097 else
1098 return nullptr;
1099 }
1100 else if( aField.CmpNoCase( wxT( "NetName" ) ) == 0 )
1101 {
1102 if( aVar == wxT( "A" ) )
1103 return std::make_unique<PCB_EXPR_NETNAME_REF>( 0 );
1104 else if( aVar == wxT( "B" ) )
1105 return std::make_unique<PCB_EXPR_NETNAME_REF>( 1 );
1106 else
1107 return nullptr;
1108 }
1109 else if( aField.CmpNoCase( wxT( "Type" ) ) == 0 )
1110 {
1111 if( aVar == wxT( "A" ) )
1112 return std::make_unique<PCB_EXPR_TYPE_REF>( 0 );
1113 else if( aVar == wxT( "B" ) )
1114 return std::make_unique<PCB_EXPR_TYPE_REF>( 1 );
1115 else
1116 return nullptr;
1117 }
1118
1119 if( aVar == wxT( "A" ) || aVar == wxT( "AB" ) )
1120 vref = std::make_unique<PCB_EXPR_VAR_REF>( 0 );
1121 else if( aVar == wxT( "B" ) )
1122 vref = std::make_unique<PCB_EXPR_VAR_REF>( 1 );
1123 else if( aVar == wxT( "L" ) )
1124 vref = std::make_unique<PCB_EXPR_VAR_REF>( 2 );
1125 else
1126 return nullptr;
1127
1128 if( aField.length() == 0 ) // return reference to base object
1129 {
1130 return std::move( vref );
1131 }
1132
1133 wxString field( aField );
1134 field.Replace( wxT( "_" ), wxT( " " ) );
1135
1136 for( const PROPERTY_MANAGER::CLASS_INFO& cls : propMgr.GetAllClasses() )
1137 {
1138 if( propMgr.IsOfType( cls.type, TYPE_HASH( BOARD_ITEM ) ) )
1139 {
1140 PROPERTY_BASE* prop = propMgr.GetProperty( cls.type, field );
1141
1142 if( prop )
1143 {
1144 vref->AddAllowedClass( cls.type, prop );
1145
1146 if( prop->TypeHash() == TYPE_HASH( int ) )
1147 {
1148 vref->SetType( LIBEVAL::VT_NUMERIC );
1149 }
1150 else if( prop->TypeHash() == TYPE_HASH( wxString ) )
1151 {
1152 vref->SetType( LIBEVAL::VT_STRING );
1153 }
1154 else if ( prop->HasChoices() )
1155 { // it's an enum, we treat it as string
1156 vref->SetType( LIBEVAL::VT_STRING );
1157 vref->SetIsEnum ( true );
1158 }
1159 else
1160 {
1161 wxFAIL_MSG( wxT( "PCB_EXPR_UCODE::createVarRef: Unknown property type." ) );
1162 }
1163 }
1164 }
1165 }
1166
1167 if( vref->GetType() == LIBEVAL::VT_UNDEFINED )
1168 vref->SetType( LIBEVAL::VT_PARSE_ERROR );
1169
1170 return std::move( vref );
1171}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:53
virtual size_t TypeHash() const =0
Return type-id of the property type.
virtual bool HasChoices() const
Return true if this PROPERTY has a limited set of possible values.
Definition: property.h:216
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:63
CLASSES_INFO GetAllClasses()
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:65
PROPERTY_BASE * GetProperty(TYPE_ID aType, const wxString &aProperty) const
Return a property for a specific type.
bool IsOfType(TYPE_ID aDerived, TYPE_ID aBase) const
Return true if aDerived is inherited from aBase.
#define TYPE_HASH(x)
Definition: property.h:59

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 189 of file libeval_compiler.cpp.

190{
191 wxString rv;
192
193 for( auto op : m_ucode )
194 {
195 rv += op->Format();
196 rv += "\n";
197 }
198
199 return rv;
200};

References LIBEVAL::UCODE::m_ucode.

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

◆ Run()

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

Definition at line 1210 of file libeval_compiler.cpp.

1211{
1212 static VALUE g_false( 0 );
1213
1214 try
1215 {
1216 for( UOP* op : m_ucode )
1217 op->Exec( ctx );
1218 }
1219 catch(...)
1220 {
1221 // rules which fail outright should not be fired
1222 return &g_false;
1223 }
1224
1225 if( ctx->SP() == 1 )
1226 {
1227 return ctx->Pop();
1228 }
1229 else
1230 {
1231 // If stack is corrupted after execution it suggests a problem with the compiler, not
1232 // the rule....
1233
1234 // do not use "assert"; it crashes outright on OSX
1235 wxASSERT( ctx->SP() == 1 );
1236
1237 // non-well-formed rules should not be fired on a release build
1238 return &g_false;
1239 }
1240}

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: