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 377 of file libeval_compiler.h.

378 {
379 m_ucode.push_back(uop);
380 }
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 180 of file pcb_expr_evaluator.cpp.

181{
183
184 return registry.Get( aName.Lower() );
185}
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 188 of file pcb_expr_evaluator.cpp.

190{
192 std::unique_ptr<PCB_EXPR_VAR_REF> vref;
193
194 // Check for a couple of very common cases and compile them straight to "object code".
195
196 if( aField.CmpNoCase( wxT( "NetClass" ) ) == 0 )
197 {
198 if( aVar == wxT( "A" ) )
199 return std::make_unique<PCB_EXPR_NETCLASS_REF>( 0 );
200 else if( aVar == wxT( "B" ) )
201 return std::make_unique<PCB_EXPR_NETCLASS_REF>( 1 );
202 else
203 return nullptr;
204 }
205 else if( aField.CmpNoCase( wxT( "NetName" ) ) == 0 )
206 {
207 if( aVar == wxT( "A" ) )
208 return std::make_unique<PCB_EXPR_NETNAME_REF>( 0 );
209 else if( aVar == wxT( "B" ) )
210 return std::make_unique<PCB_EXPR_NETNAME_REF>( 1 );
211 else
212 return nullptr;
213 }
214 else if( aField.CmpNoCase( wxT( "Type" ) ) == 0 )
215 {
216 if( aVar == wxT( "A" ) )
217 return std::make_unique<PCB_EXPR_TYPE_REF>( 0 );
218 else if( aVar == wxT( "B" ) )
219 return std::make_unique<PCB_EXPR_TYPE_REF>( 1 );
220 else
221 return nullptr;
222 }
223
224 if( aVar == wxT( "A" ) || aVar == wxT( "AB" ) )
225 vref = std::make_unique<PCB_EXPR_VAR_REF>( 0 );
226 else if( aVar == wxT( "B" ) )
227 vref = std::make_unique<PCB_EXPR_VAR_REF>( 1 );
228 else if( aVar == wxT( "L" ) )
229 vref = std::make_unique<PCB_EXPR_VAR_REF>( 2 );
230 else
231 return nullptr;
232
233 if( aField.length() == 0 ) // return reference to base object
234 {
235 return std::move( vref );
236 }
237
238 wxString field( aField );
239 field.Replace( wxT( "_" ), wxT( " " ) );
240
241 for( const PROPERTY_MANAGER::CLASS_INFO& cls : propMgr.GetAllClasses() )
242 {
243 if( propMgr.IsOfType( cls.type, TYPE_HASH( BOARD_ITEM ) ) )
244 {
245 PROPERTY_BASE* prop = propMgr.GetProperty( cls.type, field );
246
247 if( prop )
248 {
249 vref->AddAllowedClass( cls.type, prop );
250
251 if( prop->TypeHash() == TYPE_HASH( int ) )
252 {
253 vref->SetType( LIBEVAL::VT_NUMERIC );
254 }
255 else if( prop->TypeHash() == TYPE_HASH( wxString ) )
256 {
257 vref->SetType( LIBEVAL::VT_STRING );
258 }
259 else if ( prop->HasChoices() )
260 { // it's an enum, we treat it as string
261 vref->SetType( LIBEVAL::VT_STRING );
262 vref->SetIsEnum ( true );
263 }
264 else
265 {
266 wxFAIL_MSG( wxT( "PCB_EXPR_UCODE::createVarRef: Unknown property type." ) );
267 }
268 }
269 }
270 }
271
272 if( vref->GetType() == LIBEVAL::VT_UNDEFINED )
273 vref->SetType( LIBEVAL::VT_PARSE_ERROR );
274
275 return std::move( vref );
276}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:70
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:225
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:74
CLASSES_INFO GetAllClasses()
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:76
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:63

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

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

References LIBEVAL::UCODE::m_ucode.

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

◆ Run()

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

Definition at line 1235 of file libeval_compiler.cpp.

1236{
1237 static VALUE g_false( 0 );
1238
1239 try
1240 {
1241 for( UOP* op : m_ucode )
1242 op->Exec( ctx );
1243 }
1244 catch(...)
1245 {
1246 // rules which fail outright should not be fired
1247 return &g_false;
1248 }
1249
1250 if( ctx->SP() == 1 )
1251 {
1252 return ctx->Pop();
1253 }
1254 else
1255 {
1256 // If stack is corrupted after execution it suggests a problem with the compiler, not
1257 // the rule....
1258
1259 // do not use "assert"; it crashes outright on OSX
1260 wxASSERT( ctx->SP() == 1 );
1261
1262 // non-well-formed rules should not be fired on a release build
1263 return &g_false;
1264 }
1265}

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: