Formatting.

This commit is contained in:
Jeff Young 2025-06-21 19:21:43 -06:00
parent ed6440b782
commit 3284dc348a
4 changed files with 87 additions and 79 deletions

View File

@ -60,7 +60,7 @@ namespace LIBEVAL
TREE_NODE* newNode( LIBEVAL::COMPILER* compiler, int op, const T_TOKEN_VALUE& value )
{
auto t2 = new TREE_NODE();
TREE_NODE* t2 = new TREE_NODE();
t2->valid = true;
t2->value.str = value.str ? new wxString( *value.str ) : nullptr;
@ -183,10 +183,8 @@ wxString UOP::Format() const
UCODE::~UCODE()
{
for ( auto op : m_ucode )
{
for( UOP* op : m_ucode )
delete op;
}
}
@ -194,7 +192,7 @@ wxString UCODE::Dump() const
{
wxString rv;
for( auto op : m_ucode )
for( UOP* op : m_ucode )
{
rv += op->Format();
rv += "\n";
@ -295,10 +293,10 @@ void COMPILER::Clear()
m_tree = nullptr;
for( auto tok : m_gcItems )
for( TREE_NODE* tok : m_gcItems )
delete tok;
for( auto tok: m_gcStrings )
for( wxString* tok: m_gcStrings )
delete tok;
m_gcItems.clear();
@ -839,8 +837,7 @@ bool COMPILER::generateUCode( UCODE* aCode, CONTEXT* aPreflightContext )
{
TREE_NODE* node = stack.back();
libeval_dbg( 4, "process node %p [op %d] [stack %lu]\n",
node, node->op, (unsigned long)stack.size() );
libeval_dbg( 4, "process node %p [op %d] [stack %lu]\n", node, node->op, (unsigned long)stack.size() );
// process terminal nodes first
switch( node->op )
@ -848,10 +845,7 @@ bool COMPILER::generateUCode( UCODE* aCode, CONTEXT* aPreflightContext )
case TR_OP_FUNC_CALL:
// Function call's uop was generated inside TR_STRUCT_REF
if( !node->uop )
{
reportError( CST_CODEGEN, _( "Unknown parent of function parameters" ),
node->srcPos );
}
reportError( CST_CODEGEN, _( "Unknown parent of function parameters" ), node->srcPos );
node->isTerminal = true;
break;
@ -892,14 +886,12 @@ bool COMPILER::generateUCode( UCODE* aCode, CONTEXT* aPreflightContext )
if( !vref )
{
msg.Printf( _( "Unrecognized item '%s'" ), itemName );
reportError( CST_CODEGEN, msg,
node->leaf[0]->srcPos - (int) itemName.length() );
reportError( CST_CODEGEN, msg, node->leaf[0]->srcPos - (int) itemName.length() );
}
else if( vref->GetType() == VT_PARSE_ERROR )
{
msg.Printf( _( "Unrecognized property '%s'" ), propName );
reportError( CST_CODEGEN, msg,
node->leaf[1]->srcPos - (int) propName.length() );
reportError( CST_CODEGEN, msg, node->leaf[1]->srcPos - (int) propName.length() );
}
node->leaf[0]->isVisited = true;
@ -922,8 +914,7 @@ bool COMPILER::generateUCode( UCODE* aCode, CONTEXT* aPreflightContext )
if( !vref )
{
msg.Printf( _( "Unrecognized item '%s'" ), itemName );
reportError( CST_CODEGEN, msg,
node->leaf[0]->srcPos - (int) itemName.length() );
reportError( CST_CODEGEN, msg, node->leaf[0]->srcPos - (int) itemName.length() );
}
wxString functionName = formatNode( node->leaf[1]->leaf[0] );
@ -996,8 +987,7 @@ bool COMPILER::generateUCode( UCODE* aCode, CONTEXT* aPreflightContext )
if( !vref )
{
msg.Printf( _( "Unrecognized item '%s'" ), itemName );
reportError( CST_CODEGEN, msg,
node->leaf[0]->srcPos - (int) itemName.length() );
reportError( CST_CODEGEN, msg, node->leaf[0]->srcPos - (int) itemName.length() );
}
msg.Printf( _( "Unrecognized property '%s'" ), propName );
@ -1251,7 +1241,7 @@ void UOP::Exec( CONTEXT* ctx )
break;
}
auto rp = ctx->AllocValue();
VALUE* rp = ctx->AllocValue();
rp->Set( result );
rp->SetUnits( resultUnits );
ctx->Push( rp );
@ -1274,7 +1264,7 @@ void UOP::Exec( CONTEXT* ctx )
break;
}
auto rp = ctx->AllocValue();
VALUE* rp = ctx->AllocValue();
rp->Set( result );
rp->SetUnits( resultUnits );
ctx->Push( rp );

View File

@ -196,16 +196,32 @@ class KICOMMON_API VALUE
{
public:
VALUE() :
m_type( VT_UNDEFINED ), m_valueDbl( 0 ), m_stringIsWildcard( false ), m_isDeferredDbl( false ),
m_isDeferredStr( false ), m_units( EDA_UNITS::UNSCALED ) {};
m_type( VT_UNDEFINED ),
m_valueDbl( 0 ),
m_stringIsWildcard( false ),
m_isDeferredDbl( false ),
m_isDeferredStr( false ),
m_units( EDA_UNITS::UNSCALED )
{};
VALUE( const wxString& aStr, bool aIsWildcard = false ) :
m_type( VT_STRING ), m_valueDbl( 0 ), m_valueStr( aStr ), m_stringIsWildcard( aIsWildcard ),
m_isDeferredDbl( false ), m_isDeferredStr( false ), m_units( EDA_UNITS::UNSCALED ) {};
m_type( VT_STRING ),
m_valueDbl( 0 ),
m_valueStr( aStr ),
m_stringIsWildcard( aIsWildcard ),
m_isDeferredDbl( false ),
m_isDeferredStr( false ),
m_units( EDA_UNITS::UNSCALED )
{};
VALUE( const double aVal ) :
m_type( VT_NUMERIC ), m_valueDbl( aVal ), m_stringIsWildcard( false ), m_isDeferredDbl( false ),
m_isDeferredStr( false ), m_units( EDA_UNITS::UNSCALED ) {};
m_type( VT_NUMERIC ),
m_valueDbl( aVal ),
m_stringIsWildcard( false ),
m_isDeferredDbl( false ),
m_isDeferredStr( false ),
m_units( EDA_UNITS::UNSCALED )
{};
static VALUE* MakeNullValue()
{

View File

@ -427,34 +427,35 @@ void DRC_RULES_PARSER::parseConstraint( DRC_RULE* aRule )
auto validateAndSetValueWithUnits =
[this, &allowsTimeDomain, &unitsType, &c]( int aValue, const EDA_UNITS aUnits, auto aSetter )
{
const EDA_DATA_TYPE unitsTypeTmp = UNITS_PROVIDER::GetTypeFromUnits( aUnits );
if( !allowsTimeDomain && unitsTypeTmp == EDA_DATA_TYPE::TIME )
reportError( _( "Time based units not allowed for constraint type." ) );
if( ( c.m_Value.HasMin() || c.m_Value.HasMax() || c.m_Value.HasOpt() ) && unitsType != unitsTypeTmp )
{
reportError( _( "Mixed units for constraint values." ) );
}
unitsType = unitsTypeTmp;
aSetter( aValue );
if( allowsTimeDomain )
{
if( unitsType == EDA_DATA_TYPE::TIME )
{
c.SetOption( DRC_CONSTRAINT::OPTIONS::TIME_DOMAIN );
c.ClearOption( DRC_CONSTRAINT::OPTIONS::SPACE_DOMAIN );
}
else
{
c.SetOption( DRC_CONSTRAINT::OPTIONS::SPACE_DOMAIN );
c.ClearOption( DRC_CONSTRAINT::OPTIONS::TIME_DOMAIN );
}
}
};
const EDA_DATA_TYPE unitsTypeTmp = UNITS_PROVIDER::GetTypeFromUnits( aUnits );
if( !allowsTimeDomain && unitsTypeTmp == EDA_DATA_TYPE::TIME )
reportError( _( "Time based units not allowed for constraint type." ) );
if( ( c.m_Value.HasMin() || c.m_Value.HasMax() || c.m_Value.HasOpt() )
&& unitsType != unitsTypeTmp )
{
reportError( _( "Mixed units for constraint values." ) );
}
unitsType = unitsTypeTmp;
aSetter( aValue );
if( allowsTimeDomain )
{
if( unitsType == EDA_DATA_TYPE::TIME )
{
c.SetOption( DRC_CONSTRAINT::OPTIONS::TIME_DOMAIN );
c.ClearOption( DRC_CONSTRAINT::OPTIONS::SPACE_DOMAIN );
}
else
{
c.SetOption( DRC_CONSTRAINT::OPTIONS::SPACE_DOMAIN );
c.ClearOption( DRC_CONSTRAINT::OPTIONS::TIME_DOMAIN );
}
}
};
T token = NextTok();
@ -790,26 +791,27 @@ void DRC_RULES_PARSER::parseValueWithUnits( const wxString& aExpr, int& aResult,
aResult = 0.0;
aUnits = EDA_UNITS::UNSCALED;
auto errorHandler = [&]( const wxString& aMessage, int aOffset )
{
wxString rest;
wxString first = aMessage.BeforeFirst( '|', &rest );
auto errorHandler =
[&]( const wxString& aMessage, int aOffset )
{
wxString rest;
wxString first = aMessage.BeforeFirst( '|', &rest );
if( m_reporter )
{
wxString msg = wxString::Format( _( "ERROR: <a href='%d:%d'>%s</a>%s" ),
CurLineNumber(), CurOffset() + aOffset, first, rest );
if( m_reporter )
{
wxString msg = wxString::Format( _( "ERROR: <a href='%d:%d'>%s</a>%s" ),
CurLineNumber(), CurOffset() + aOffset, first, rest );
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
}
else
{
wxString msg = wxString::Format( _( "ERROR: %s%s" ), first, rest );
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
}
else
{
wxString msg = wxString::Format( _( "ERROR: %s%s" ), first, rest );
THROW_PARSE_ERROR( msg, CurSource(), CurLine(), CurLineNumber(),
CurOffset() + aOffset );
}
};
THROW_PARSE_ERROR( msg, CurSource(), CurLine(), CurLineNumber(),
CurOffset() + aOffset );
}
};
PCBEXPR_EVALUATOR evaluator( aUnitless ? (LIBEVAL::UNIT_RESOLVER*) new PCBEXPR_UNITLESS_RESOLVER()
: (LIBEVAL::UNIT_RESOLVER*) new PCBEXPR_UNIT_RESOLVER() );

View File

@ -168,7 +168,7 @@ public:
{
// Test constituent net class names. The effective net class name (e.g. CLASS1,CLASS2,OTHER_CLASS) is
// tested in the fallthrough condition.
for( const auto nc : m_item->GetEffectiveNetClass()->GetConstituentNetclasses() )
for( const NETCLASS* nc : m_item->GetEffectiveNetClass()->GetConstituentNetclasses() )
{
const wxString& ncName = nc->GetName();
@ -198,7 +198,7 @@ public:
// Test constituent net class names
bool isInConstituents = false;
for( const auto nc : m_item->GetEffectiveNetClass()->GetConstituentNetclasses() )
for( const NETCLASS* nc : m_item->GetEffectiveNetClass()->GetConstituentNetclasses() )
{
const wxString& ncName = nc->GetName();
@ -270,7 +270,7 @@ public:
{
// Test constituent component class names. The effective component class name
// (e.g. CLASS1,CLASS2,OTHER_CLASS) is tested in the fallthrough condition.
for( const auto cc : m_item->GetComponentClass()->GetConstituentClasses() )
for( const COMPONENT_CLASS* cc : m_item->GetComponentClass()->GetConstituentClasses() )
{
const wxString& ccName = cc->GetName();
@ -308,7 +308,7 @@ public:
// Test constituent component class names
bool isInConstituents = false;
for( const auto cc : m_item->GetComponentClass()->GetConstituentClasses() )
for( const COMPONENT_CLASS* cc : m_item->GetComponentClass()->GetConstituentClasses() )
{
const wxString& ccName = cc->GetName();
@ -410,7 +410,7 @@ LIBEVAL::VALUE* PCBEXPR_VAR_REF::GetValue( LIBEVAL::CONTEXT* aCtx )
{
if( m_isOptional )
{
auto val = item->Get<std::optional<int>>( it->second );
std::optional<int> val = item->Get<std::optional<int>>( it->second );
if( val.has_value() )
return new LIBEVAL::VALUE( static_cast<double>( val.value() ) );
@ -424,7 +424,7 @@ LIBEVAL::VALUE* PCBEXPR_VAR_REF::GetValue( LIBEVAL::CONTEXT* aCtx )
{
if( m_isOptional )
{
auto val = item->Get<std::optional<double>>( it->second );
std::optional<double> val = item->Get<std::optional<double>>( it->second );
if( val.has_value() )
return new LIBEVAL::VALUE( val.value() );